Guilherme Polo wrote: > On Mon, Aug 25, 2008 at 7:20 AM, Ken Seehart <ken at seehart.com> wrote: > >> I'm using SocketServer to implement a local server that serves comet >> long-polling connections. >> >> How do I increase the maximum number of open connections? Currently it is >> limited to about 8 I think. More than that and it seems to block on opening >> more connections until one of the other connections releases. >> > > You need to change request_queue_size in your subclass, supposing you > are directly or indirectly using a tcp server. > The default is 5, rather low. The first attempt you can do is using > the socket.SOMAXCONN value, but depending on your system you can set a > number much higher than that one given by socket.SOMAXCONN. > Also be aware that "request_queue_size" determines the max. number of incoming connections that are waiting in a queue to be accepted by the server. After the server calls accept() on the server socket, the connection is removed from the queue and a new client socket is created. The actual communication is done through the client socket(s). The number of open client sockets is independent of the request queue size. In other words, if you accept incoming connections instantly and then process clients in parallel, then probably you do not need to increase the queue size. (Maybe you already knew that?) Best, Laszlo
大意就是,如果你的socket handle请求的时候是同步的,那么设置这个 socket.SOMAXCONN是会影响到最大的,正在等待接受的连接数的,但是,如果你的server是parallel的,那么即使设置了也没什么效果,连接数量,只与你控制的,最大线程数量有关系。
具体的 socket.SOMAXCONN 的作用,可以参阅TCP原理的相关文章。