24

The sysctl option net.core.somaxconn defaults to 128 (on our systems) but can be raised.

  1. What exactly is this limit measuring and capping?

  2. How do I find out how close I am to the limit?

Context: I had a problem recently that appeared to be corrected by raising this limit. The problem was intermittent, so I don't trust that it is really fixed. I would like to find out if the current number of [whatever this setting caps] is greater than the previous maximum limit of 128.

Andrew
  • 1,134
  • 3
  • 10
  • 16
  • 1
    FYI: [since Linux 5.4 it was increased to 4096](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=19f92a030ca6d772ab44b22ee6a01378a8cb32d4). – Hi-Angel Nov 23 '19 at 10:53

1 Answers1

26

somaxconn determines the maximum number of backlogged connections allowed for each TCP port on the system. Increasing it (recommended for servers) can prevent "connection refused" messages, but it can result in slow connections if the server can't handle the increased load.

You can check the current backlog with netstat -ant | grep -c SYN_REC according to this page. It will count how many connections are in the "SYN received" state, meaning the system has received a SYN packet (connection request) but hasn't acknowledged it yet.

If your system has ss installed, you can also use ss -s to display a summary of connections. Look for synrecv in the output, or ss -s | grep -Po '(?<=synrecv )\d+(?=,)' to just print the number.

miken32
  • 942
  • 1
  • 13
  • 35