10

I've done a couple of years of large-scale game server development in PHP. A load balancer delegates incoming requests to one server in a cluster. In the name of better performance, we began caching all static data (essentially the game world's model objects) on each of the instances in that cluster, directly in Apache shared memory, using apc_store and apc_fetch.

For a number of reasons, we're now beginning to develop a similar game framework in Python, using the Flask microframework. At first glance, this instance's memory store is the one piece that doesn't appear to translate directly to Python/Flask. We're presently considering running Memcached locally on each instance (to avoid streaming fairly large model objects over-the-wire from our main Memcached cluster.)

What can we use instead?

2 Answers 2

5

I would think that even in this case you might want to consider having a centralized key/value store system rather than a series of independent ones on each server. Unless your load balancer always redirects the same users to the same servers you could run into a case where a user's requests are routed to different servers each time so each node would have to retrieve the game state instead of accessing it from a shared cache.

Also the memory strain that a local key/value store on each system might incur could slow down your game server's other functions. Though that largely depends on the amount of data being cached.

In general the best approach would be to run some benchmarks to see what kind of performance you'd get with a memcached cluster and the types of objects you're storing vs local storage.

Depending on what other features you want from you key/value store you might also want to look into some alternatives like mongodb (http://www.mongodb.org/).

6
  • I use centralized Membase for my true data store, and centralized Memcache for ephemeral key/value. As I mentioned in my post, the point is "to avoid streaming fairly large model objects over-the-wire from our main Memcached cluster". Making this change to local memory in a previous game gave me a huge performance boost. The entire static data set for a game like this is under 50mb, so storage/load isn't an issue. After all, you're going to have to pull it into local memory eventually anyway; all the better if it's stored there to begin with :)
    – Kyle Wild
    Feb 16, 2011 at 17:59
  • The basic premise is that data that must be centralized should be centralized, and data than can be pushed to app servers (i.e. static/game world data that is stateless and identical across nodes) should be pushed to the app servers.
    – Kyle Wild
    Feb 16, 2011 at 18:00
  • Sorry I can't accept this answer as it ignores two important points from my quest: [1] I'm only talking about static data, and [2] I already use centralized Memcached.
    – Kyle Wild
    Feb 16, 2011 at 18:04
  • 1
    Okay, I understand now, I assumed that the static data was still per-user (for their instance of the game) and not shared. So your equivalence in Flask for the apc_store and apc_fetch would be to use the Werkzeug cache library link which at least provides you an abstraction to which system you want to use for caching in the end (even if you decide to use memcached)
    – efalconer
    Feb 16, 2011 at 20:18
  • I wonder also if you could use something like membase server link and have an instance running on each of your servers. Then you could use it to replicate the static content to all of the nodes, but each server could connect to its local instance. Not something I have direct experience with, but it may work in this instance.
    – efalconer
    Feb 16, 2011 at 20:22
2

[Five-months later]

Our game framework is done.

In the end, we decided to store the static data in fully initialized sqlalchemy model instances in each web server. When a newly-booted game server is warming up, these instances are first constructed by hitting a shared MySQL db.

Since our Model factories defer to an instance pool, the Model instances need only be constructed once per deployment per server – this is important, because at our scale, MySQL would weep under any sort of ongoing load. We accomplished our goal of not streaming this data over the wire by keeping the item definitions as close to our app code as possible: in the app code itself.

I now realize that my original question was naive, because unlike in the LAMP stack, the Flask server keeps running between requests, the server's memory itself is "shared memory" – there's no need for something like APC to make it so. In fact, anything outside of the request processing scope it self and Flask's threadsafe local store, can be considered "shared memory".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.