Python sock.listen(...) [英] Python sock.listen(...)
问题描述
所有的例子我看到的 sock.listen(5)
在python文档建议我应该设置最大积压量为 5
。这是我的应用程序的一个问题,因为我期待一些非常高的卷(许多并发连接)。我把它设置为200,没有看到我的系统上的任何问题,但是想知道我可以在它导致问题之前有多高。
有人知道吗? / p>
编辑:这是我的accept()循环。
try:
self.q.put(sock.accept())
except KeyboardInterrupt:
break
except Exception,e:
self.log (ERR%s%e)
说
socket.listen(backlog)
做到插座。
backlog参数指定排队连接的最大值
,
应至少为1;最大
值是系统依赖的(通常为5)。
显然系统值超过5的值。我不明白为什么设置一个更大的数字将是一个问题。也许一些内存是为每个排队的连接保留的。
我的linux手册页有这个说法
如果backlog参数大于
/ proc / sys / net / core / somaxconn中的值,那么
将被静默截断到该值;
此
文件中的默认值为128.在2.4.25之前的内核中,此限制是硬编码值SOMAXCONN,值为128.
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.
这篇关于Python sock.listen(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!