python listen_Python sock.listen(...)

All the examples I've seen of sock.listen(5) in the python documentation suggest I should set the max backlog number to be 5. This is causing a problem for my app since I'm expecting some very high volume (many concurrent connections). I set it to 200 and haven't seen any problems on my system, but was wondering how high I can set it before it causes problems..

Anyone know?

Edit: Here's my accept() loop.

while True:

try:

self.q.put(sock.accept())

except KeyboardInterrupt:

break

except Exception, e:

self.log("ERR %s" % e)

解决方案

The doc say this

socket.listen(backlog) Listen for

connections made to the socket. The

backlog argument specifies the maximum

number of queued connections and

should be at least 1; the maximum

value is system-dependent (usually 5).

Obviously the system value is more than 5 on your system. I don't see why setting it to a larger number would be a problem. Perhaps some memory is reserved for each queued connection.

My linux man page has this to say

If the backlog argument is greater than the value in

/proc/sys/net/core/somaxconn, then it

is silently truncated to that value;

the default value in this

file is 128. In kernels before 2.4.25, this limit was a hard coded value, SOMAXCONN, with the value 128.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值