Take the 2-minute tour ×

I have few question about writing game server, I hope that someone have experience from practice, and will help me.

I'm developing server for Flash game (MMO avatar game) using python and twisted. This is first time that I Use twisted and also first time that I write game server, and I have few question about server design, and twisted implementation.

  1. Does anybody have practice experience or some case study about twisted performance in "game server situations" (talk to each other, talk to everyone in room, walking etc. - avatar are grouped by 50 in each room. There are also other actions but this is most common). How many users twisted can handle? (Is real to expect 10K users per server)

  2. Epoll reactor? Is this good choice for MMO game server?

  3. How to build server monitoring and administration? If i want to disconnect some users, or take any action when server is already running? One of solution is to write data from Protocol and Factory in memcache server, then processing and displaying in web interface, but this is one way communication and it's "expensive", I need that information on request, not always. Is there some good way to build "console" for monitoring and administration? I was searching online but I didn't find any example or text about that, and here is my idea:

Create server with one Factory and two Protocol? One protocol for game, one for administration. (one factory<->protocol listen port 1234, second factory<->protocol listen 1235). I have all information that i need in factory (number of users, number of active rooms, etc), and also admin can easy read that information because they share same factory. But one factory one protocol so I made few modification:

Two factories two protocols, and one factory is passed to another as reference. In practice something like this:

from twisted.internet.protocol import Factory, Protocol
from twisted.protocols import basic
from twisted.internet import reactor
from twisted.application import service, internet

class Game(Protocol):
    def connectionMade(self):

    def dataReceiver(self, data):
            for user in self.factory.users:

    def connectionLost(self, why):
            self.transport.write("You are off: {0}".format(why))

class GameFactory(Factory):
    users = []
    protocol = Game

class Admin(basic.LineReceiver):
    def lineReceived(self, line):
            if line == 'stats':
                    self.transport.write("{0} users online\n".format(self.factory.stats()))

            if line[0:4] == 'kill':

    def connectionMade(self):
            self.transport.write("hello fanta\n")

class AdminFactory(Factory):
    protocol = Admin

    def __init__(self, GameFactory):
            self.GameFactory = GameFactory

    def stats(self):
            return len(self.GameFactory.users)

    def kill(self, id):

application = service.Application("game")
gf = GameFactory()

internet.TCPServer(1234, gf).setServiceParent(application)
internet.TCPServer(1235, AdminFactory(gf)).setServiceParent(application)

Is this good solution? Doesn't affect GameFactory performances? Do any have better solution, proposition? As I said I'm totally new in writing game servers (any kind of servers) so i need help about organisation and design.

share|improve this question

1 Answer 1

twisted.conch.manhole is one possibility for monitoring/administration. Ultimately you'll probably want a number of control interfaces for different purposes. Don't be afraid to setup a web server on another port, an IRC server on another, perhaps an SMTP client to email you statistics at the end of the day - this is the whole point of Twisted. You'll mostly pay for the number of connections, rather than the number of services.

Try not to worry about performance until you load test your first attempt and confirm it's too slow, you may find that your current setup is more than fast enough for what you need. If not, try using UDP for certain aspects of player communication (such as location), and a message queue for player chat. Second Life wrote an overview of some popular message queue implementations.

Good luck.

share|improve this answer

Your Answer


