确定TCP listen()队列中当前积压的连接数 [英] Determine the current number of backlogged connections in TCP listen() queue
问题描述
是否可以找到在Linux上的TCP套接字上等待当前个连接尝试的接受次数?
Is there a way to find out the current number of connection attempts awaiting accept() on a TCP socket on Linux?
我想我可以在每个事件循环上点击EWOULDBLOCK之前计算成功的accepts()的数量,但是我使用的是隐藏这些细节的高级库(Python/Twisted).而且它使用的是epoll()而不是老式的select()/poll()循环.
I suppose I could count the number of accepts() that succeed before hitting EWOULDBLOCK on each event loop, but I'm using a high-level library (Python/Twisted) that hides these details. Also it's using epoll() rather than an old-fashioned select()/poll() loop.
我正在试图大致了解高性能无阻塞网络服务器上的负载,我认为这个数字可以很好地表征.平均负载/CPU统计信息无济于事,因为我在并发工作进程中执行大量磁盘I/O. Linux上的大多数这些统计信息都将等待磁盘I/O所花费的时间作为负载的一部分(对于我的特定服务器体系结构而言,不是). accept()和响应之间的延迟也不是一个好方法,因为一旦服务器处理了每个请求,通常很快就会处理每个请求.我只是想找出我离服务器无法以比传入请求更快的速度分发请求的中断点有多近.
I am trying to get a general sense of the load on a high-performance non-blocking network server, and I think this number would be a good characterization. Load average/CPU statistics aren't helping much, because I'm doing a lot of disk I/O in concurrent worker processes. Most of these stats on Linux count time spent waiting on disk I/O as part of the load (which it isn't, for my particular server architecture). Latency between accept() and response isn't a good measure either, since each request usually gets processed very quickly once the server gets around to it. I'm just trying to find out how close I am to reaching a breaking point where the server can't dispatch requests faster than they are coming in.
推荐答案
例如,在检查端口80时,您可以查看ss
输出中的unacked
值:
You can look at the unacked
value in the output of ss
, for example when examining port 80:
ss -lti '( sport = :http )'
输出看起来像这样:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 123 0 :::http :::*
rto:0.99 mss:536 cwnd:10 unacked:123
(有关内核源代码和所有资源的)详细证明,unacked
确实是TCP连接积压,请参见详细文章"Apache TCP Backlog" .请注意,您可能需要一个新版本的ss
才能包含unacked
输出.至少我的(iproute2-ss131122
)没有提供它.
For a detailed proof (with kernel sources and all) that unacked
is indeed the TCP connection backlog, see the detailed article "Apache TCP Backlog" by Ryan Frantz. Note that you may need a pretty new version of ss
for the unacked
output to be included. At least mine (iproute2-ss131122
) does not provide it.
这篇关于确定TCP listen()队列中当前积压的连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!