11

In a typical C network server implementation, the size of the accept pending queue can be set with listen. When a new connection incomes and there is no more space in the queue, ECONNREFUSED is send to the client or the request is ignored.

Is any way to know the state of this queue? It's important because in a high load event-based daemon, we're detecting some retries from the client, and we suspect that this queue goes full and the connection tries are being ignored.

Thanks in advance.

meshy
  • 7,387
  • 7
  • 45
  • 68
  • Does the client receive an ECONNREFUSED error? If so, you have your answer. AFAIK there's no way to know the pending queue's size. – Simone Jan 27 '11 at 10:09
  • Not exactly. The handshake is not correctly finished and the server goes into retries sending the SYNACK like the last ACK of the handshake has been lost. We've reproduced this behavior when the accept pending queue goes out from the limit set with listen, so this queue is our suspect. – Jon Ander Ortiz Durántez Jan 27 '11 at 10:16
  • Are you sure you accept every incoming connection? – Simone Jan 27 '11 at 10:52
  • Simone: Yes, in the event loop when a read callback goes from the listening socket, we accept connections until accept goes to error (with EAGAIN, sockets are nonblockeant). The target of the question is to determine if while we are doing the rest of operations of the event loop (there are many socket monitorized in the same event loop that the listening socket) the accept queue goes over, and the connection attempts are discarded. – Jon Ander Ortiz Durántez Jan 27 '11 at 11:48
  • Ander: Note that if you set `/proc/sys/net/ipv4/tcp_abort_on_overflow` to 1, it will reset overflowing connections instead. – caf Jan 28 '11 at 01:44
  • 1
    Cat: Yes, i know. BTW, i've found another way to look the number of connections waiting in the accept socket. In /proc/net/tcp, the 0A status sockets are in listening state. The rx_queue sets the number of bytes pending to read, and in the listening sockets, the accept pending connections. – Jon Ander Ortiz Durántez Sep 12 '11 at 19:11

1 Answers1

9

in linux: /proc/sys/net/ipv4/tcp_max_syn_backlog:

Maximal number of remembered connection requests, which are still did not receive an acknowledgment from connecting client.

Default value is 1024 for systems with more than 128Mb of memory, and 128 for low memory machines. If server suffers of overload, try to increase this number.

/proc/sys/net/core/somaxconn: Limit of socket listen() backlog, known in userspace as SOMAXCONN. Defaults to 128. See also tcp_max_syn_backlog for additional tuning for TCP sockets.

these are the relevant sysctls .. on openbsd that i am sitting now a quick sysctl -a reveals: net.inet.ip.maxqueue=300

ramrunner
  • 151
  • 4