Handling thousand of persistent TCP connection with python

2.6k views Asked by At

I need to develop an application in Python handling a few thousand of persistent TCP connection in parallel. Clients connected to the server at bootstrap and send some message (in binary format) from time to time. The server also send both in reply to clients' message and asynchronously some other binary messages. Basically it is a persistent connection initiated by the client because I have no way to reach clients that are behind a NAT.

The question is: which is the libraries/framework i shall consider for this task. Spawning a thread for each client is not an option. I'm not aware of thread pool library for python. I also recently discovered gevent. Which other options do I have?

2

There are 2 answers

0
Hans Then On

'greenlets' is a leighweight concurrency package. See http://greenlet.readthedocs.org/en/latest/. Besides greenlets, you might also want to consider multiprocessing. See http://docs.python.org/2/library/multiprocessing.html.

1
Prahalad Deshpande On

This link is an excellent read. It lists all the available event driven and asynchronous network frameworks within Python and also has good analysis of the performance for each framework.

It appears that the Tornado framework is one of the most-performant when developing such applications.

Hope this helps