Jump to content
  • Advertisement
Sign in to follow this  
sipickles

Stackless Python - for whole server or just AI?

This topic is 3777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I would guess my server is about 25% complete, written in C++. I was going to use Python as its scripting language, having already had limited success extending and embedding with boost.python. Recently I've come across Stackless Python and it sounds very interesting. I hope to use that for scripting, but then it occurred to me, Where should C++ stop and stackless takeover? Should Stackless just do AI/Dynamic Content Generation,etc or all aspects like object movement, creation and destruction? If fact, scrub the c++? Some articles seem to hint that they are entirely stackless python (or am I wrong?). I primarily chose c++ for the speed factor (and my skill level!), but I do have python experience (my tools are all written in python). Can python really compete in terms of speed for the whole server? Your thoughts appreciated thanks Simon

Share this post


Link to post
Share on other sites
Advertisement
90% of the server doesn't have to be perfectly optimised, only the slow bits. Those bits, you do in C++. The rest, you do in Python. I believe Eve Online worked this way. Besides which, it's not uncommon for Python code to be quicker than a typical C++ implementation of the same feature, because the Python data structures are written by better C/C++ programmers than most of us.

Python isn't designed to be used as a scripting language anyway. You tend to end up having to work around fundamental things, or using multiple interpreters.

However, the other thing to bear in mind when running massive online games, is that once you have distributed load balancing, CPU power is cheap. It's ok for your server to be half the speed because you can just run double the servers, and it still works out cheaper than taking twice as long to code it, as you might do using C++ throughout. (Running costs are mostly bandwidth, which won't change.) I expect Python developers would be taking this approach.

Share this post


Link to post
Share on other sites
The proper answer is: the bits you profile and find to be slow. The first step is to use psyco to speed them up. Profile again: if it's still not fast enough, rewrite them in pyrex. Profile again. Still too slow? Then go down the C++ route: either Boost::python or similar, or write a dll and import it with ctypes. The key thing is to keep everything modular and encapsulated. Then if you need to rewrite a module in C++, you just do that, import it as normal, and nothing else needs to change.

What you're most likely to find slow will depend on what sort of game you're doing. Often, operations are not so much slow, as dependent on something else (eg. networking, database access) and proper use of something like Stackless makes that go away. So it's hard to guess where the suboptimal stuff will be - perhaps area of interest management, perhaps NPC AI, perhaps pathfinding, who knows. When I did optimisation on our MMO (C++ based) the slow bits were not at all where we expected, and I think yours won't be either!

Share this post


Link to post
Share on other sites
I write what I'm paid to write, not what I would choose to write. ;) If it was my choice, then yes, I would go with Python on the server side.

Share this post


Link to post
Share on other sites
Sure! Thats really helpful - Oh well its only 8000 lines of c++ server code, probably all fit for the recycle bin anyway!

Finally, please tell me theres a more sophisticated profiling tool than timeit.py!

Share this post


Link to post
Share on other sites
Quote:
Original post by sipickles
Sure! Thats really helpful - Oh well its only 8000 lines of c++ server code, probably all fit for the recycle bin anyway!

Finally, please tell me theres a more sophisticated profiling tool than timeit.py!


Well, I am not explicitly recommending you throw anything away. You may do better by wrapping some of it, I don't know.

The Python standard library has a couple of profiler modules, and some Python IDEs have reasonable interfaces to these, I believe.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!