Frage

I am now writing a unicast chat server model, the flow will be as follows:

  • Sender send out message to the chat server, in the message the server also specify the message recipient id
  • The chat server will route the message to the right client, based on the recipient id

I implemented the chat server model using python standard library asyncore. I found that the CPU goes up, once the client connect to the server (1% vs 24%). I believe the performance is limited by the looping of the handle_write function.

Is there a better (e.g. more efficient) framework to accomplish my chat server requirement?

Thanks in advance

War es hilfreich?

Lösung

Of course we'd need actual code to debug the problem. But what you're mainly asking is:

Is there a better (e.g. more efficient) framework to accomplish my chat implementation?

Yes. It's generally accepted that asyncore sucks. It's hard to use as well as being inefficient. It's especially bad on Windows, because select especially sucks on Windows.

So, yes, using a different framework will probably make things better.

Unfortunately, an SO question is not a good place to get recommendations for frameworks, but I can throw out a list of usual suspects: twisted, monocle, gevent, eventlet, tulip.

Alternatively, if you're not worried about scalability to more than a few dozen clients, just about performance at the small scale, using a thread per client (or even two threads, one for reads and one for writes) and blocking I/O is incredibly simple.

Finally, if you're staying up to date with Python 3.x, there's a good chance that 3.4 will have a new and improved async I/O module that's much more efficient and much easier to use than asyncore (and it will almost certainly be based on tulip). So… the best solution may be to get a time machine and go forward a few months. (Or, if you're a reader searching for this answer in the future, look in the standard library under IPC and guess which module is the new-and-improved async I/O module.)

Andere Tipps

I just read from a web, talking about the efficiency between different python web servers (Link).

I think I will use gevent as it is very efficient (seems).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top