title: Python twisted game server monitoring
body: <p>I have few question about writing game server, I hope that someone have experience from practice, and will help me. </p>
  
  <p>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.</p>
  
  <ol>
  <li><p>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)</p></li>
  <li><p>Epoll reactor? Is this good choice for MMO game server?</p></li>
  <li><p>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:</p></li>
  </ol>
  
  <p>Create server with one Factory and two Protocol? One protocol for game, one for administration. (one factory&lt;->protocol listen port 1234, second factory&lt;->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:</p>
  
  <p>Two factories two protocols, and one factory is passed to another as reference.
  In practice something like this:</p>
  
  <pre><code>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):
              self.factory.users.append(self)
  
      def dataReceiver(self, data):
              for user in self.factory.users:
                      user.transport.write(data+"\n")
  
      def connectionLost(self, why):
              self.transport.write("You are off: {0}".format(why))
              self.factory.users.remove(self)
  
  
  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':
                      self.factory.kill(int(line[5:6]))
  
      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):
              self.GameFactory.users[id].connectionLost('die')
  
  
  
  application = service.Application("game")
  gf = GameFactory()
  
  internet.TCPServer(1234, gf).setServiceParent(application)
  internet.TCPServer(1235, AdminFactory(gf)).setServiceParent(application)
  </code></pre>
  
  <p>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.</p>