Skip to main content
GameDev.net gamedev.net
🔒 Locked

Is writing server code in Python performance suicide?

Started by opethiliac Apr 10, 2006 at 10:22 PM 5 replies 6.7k views
Original Post
opethiliac
opethiliac
Hi, I'm contemplating using Python and TwistedMatrix (http://www.twistedmatrix.com) to write the code for my company's online game back-end. The goal is to have a service-oriented network architecture as per http://www.nevrax.org/tikiwiki/tiki-index.php?page=NeLNet . Where you have a bunch of services that communicate with each other (An example for item use: Client->FrontEndService-> GameStateService->ItemService->DatabaseService). My question is, is Python fast enough to handle heavy-duty back-end server code? It will be a tremendous boost to development time if I can use Python to this end. I can deal with performance of say 90% of the same server done in C++, but of course if the results are half the speed of the equivalent C++ server the end product is useless. My doubts spring from this presentation about EVE Online (http://www.stackless.com/Members/rmtew/code/PyCon2006-StacklessEvePresentation.zip/download) . They have about 400k lines of Python code, but yet their networking code is done in a separate library (pages 4, 12-14). One would assume that if Python were fast enough they would have done their networking with it too. Anyone have any load test results for their servers done in Python, or are familiar with successful game network backends done with Python?
Oluseyi
Oluseyi
Quote:
Original post by opethiliac
My doubts spring from this presentation about EVE Online (http://www.stackless.com/Members/rmtew/code/PyCon2006-StacklessEvePresentation.zip/download) . They have about 400k lines of Python code, but yet their networking code is done in a separate library (pages 4, 12-14). One would assume that if Python were fast enough they would have done their networking with it too.

Speed isn't everything. Remember that to create POD structures in Python, you have to use the struct module and pack and unpack data for the leanest possible network transmission - an overhead that simply wouldn't exist in C.

Better to write the network library in C and expose it as a Python module, or even integrate it into a subsystem so that it is completely transparent to the Python code.
Kylotan
Kylotan
How many users do you expect to have at once? Are you aware of Psyco? Or Pyrex?

Write it in Python, with a clean and minimal interface to the networking, and use Psyco if possible. Then migrate it out to C++ later if you need.
small_duck
small_duck
I second that. Using a high-level language will let you concentrate on the gameplay, and you will make fewer mistakes and intruduce fewer bugs. When you've finished, benchmark your server. If it's too slow, profile, and if you cannot optimize any further, replace your bottleneck by a library in C++.
stodge
stodge
http://www.minionsofmirth.com uses Python for server side game logic.
---------------------http://www.stodge.net
opethiliac
opethiliac
Thanks for the responses everyone! It's nice to have such great feedback on a first post.

I spent more time researching this yesterday, and have come up with a plan that hopefully combines all the insights in the responses.

1. Prototype everything in Python + TwistedMatrix
2. Run load tests on the result
3. Try Psyco/Pyrex, run load tests
4a. If goals are met (2k-3k players handled per server), well and good
4b. If goals are not met, migrate code from Python & TwistedMatrix to C++ and ACE framework. In the meantime the client-side guys aren't left floundering.
5. Profit!!!
hplus0603
hplus0603
I would not base a real-time game infrastructure on ACE. The impression you get when you examine it is that it's much more intended for scientific and batch distributed computing, than real-time game processing.

By the way, you forgot a step in your plan:

*. When the python is too slow, run a profile, and fix the slowest parts. Repeat.

You should do a concerted effort to make Python with Psycho run fast enough, through profiling and optimization (and, of course, good algorithms and implementation), before you even start worrying about moving to C++.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.