Determine the current number of delays in the TCP queue listen ()

Is there a way to find out the current number of connection attempts waiting for accept () on a TCP socket on Linux?

I believe that I could count the number of accepts () that succeed before clicking EWOULDBLOCK on each event loop, but I use a high-level library (Python / Twisted) that hides this data. It also uses epoll (), not the old-fashioned select () / poll () loop.

I am trying to get a general idea of ​​the load on a high-performance non-blocking network server, and I think this number will be a good feature. Average load / CPU statistics don't help much because I do a lot of disk I / O in parallel workflows. Most of these Linux timestamp statistics spent disk I / O latency as part of the load (which is not for my specific server architecture). The delay between accept () and the response is also not a good measure, since each request is usually processed very quickly as soon as the server bypasses it. I'm just trying to figure out how close I am to reaching the breakpoint when the server cannot send requests faster than they arrive.

+7
python linux twisted sockets tcp
Jun 20 '12 at 19:00
source share
3 answers

The BSD Sockets APIs do not have the function I have ever seen. I doubt if this is really a useful download measure. First, you do not expect pooling by clients, and you also think that latency fully manifests itself as pending connections. But since you cannot get the number in any case, this is a moot point.

+2
Jun 20 2018-12-12T00:
source share

Assuming that cookies SYN files are not enabled (or were not called due to the volume), I think you should get an approximate figure by simply looking at the netstat output and finding out how many connections targeting your port are in SYN_RECV state.

Here is a bit of a Python hack that will get this figure for a given listening port:

!/usr/bin/python import sys STATE_SYN_RECV = '03' def count_state(find_port, find_state): count = 0 with open('/proc/net/tcp', 'r') as f: first = True for line in f: if first: first = False continue entries = line.split() local_addr, local_port = entries[1].split(':') local_port = int(local_port, 16) if local_port != find_port: continue state = entries[3] if state == find_state: count += 1 return count if __name__ == '__main__': if len(sys.argv) != 2: print "Usage: count_syn_recv.py <port>" sys.exit(1) port = int(sys.argv[1]) count = count_state(port, STATE_SYN_RECV) print "syn_recv_count=%d" % count 
+2
Nov 14
source share

You can look at the unacked value in the ss output, for example, when checking port 80:

 ss -lti '( sport = :http )' 

The output might look like this:

 State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 123 0 :::http :::* rto:0.99 mss:536 cwnd:10 unacked:123 

Detailed proof (from an unacked kernel and all) that non- unacked is really a TCP connection backlog, see Ryan Franz's detailed article " unacked Apache TCP" . Please note that you may need a fairly new version of ss so that non- unacked output is included. At least mine ( iproute2-ss131122 ) does not provide this.

+2
Feb 21 '17 at 0:36
source share



All Articles