Python socket server 最大连接数设置

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原理的相关文章。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值