17

I have a listening socket on port 80 on ubuntu linux.

tcp    0  0 0.0.0.0:80      0.0.0.0:*   LISTEN  12248/nginx

Is there any way to get backlog value of that socket (backlog value that was sent to listen() call)?

I know that I could view the nginx configuration but configuration file could be changed without reloading nginx with new configuration, so the backlog argument in configuration and in actual LISTEN call could be different.

3 Answers 3

30

ss -lt gives this value in the Send-Q column.

5
  • 1
    This shows what the max value is, is there a way to see how many requests are currently queued in the backlog on the socket?
    – Schneems
    Apr 30, 2018 at 17:33
  • 3
    Schneems, you should be able to see that in the other column (Recv-Q). For instance, create a server that listens on a socket but never accepts. If you telnet four times and leave that running in the background, you should see Recv-Q with a value of 4.
    – Ciro Costa
    Oct 20, 2018 at 23:44
  • 1
    Note that the value that you see in Send-Q (the effective backlog size for such socket) might be different from the value set by the user in the listen(2) syscall. That's because Linux will make use of /proc/sys/net/core/somaxconn as a ceiling and change the backlog value based on that (see net/socket.c#sys_listen: elixir.bootlin.com/linux/v4.15/source/net/socket.c#L1479)
    – Ciro Costa
    Oct 20, 2018 at 23:47
  • @CiroCosta That's the current size, not the maximum size. It doesn't provide the 'backlog value of that socket (backlog value that was sent to listen() call)', which is what was asked for.
    – user207421
    Dec 2, 2018 at 5:16
  • Is there a way I can change the running server backlog value in c code. Some system call or kernel hook or ioctl or something. Or the only solution is to close socket and start listening again which I think probably used in server I may be wrong
    – user786
    Oct 12, 2021 at 10:20
-1

id use the current backlog information to manage the number of connections received BECAUSE I can respond to the incoming connections and tell the sender to modify their connection interval, thus reducing (or increasing) load. I cannot control how many incoming connections I get but I can control how frequently they connect, hence keeping the backlog down and preventing timeouts on incoming connections.

in my case this happens to be a feature of the incoming connection source firmware, so it might be unique to my situation and not relevant to others.

-6

There is no standard TCP API for getting the backlog. There is also no reason to need it. You created the socket, you put it into listen state, you should know what backlog you specified. Th system is entitled to adjust it up or down, but even then there is nothing useful you can do you with that information in your application.

5
  • 6
    There is nothing useful to do with that information, as there was No point on having more than 640K of RAM.
    – Chucky
    Apr 15, 2015 at 14:53
  • @Chucky The fact is that in the 35-ish years since the BSD Sockets API was designed nobody has seen fit to add such a function, which indicates that no use fort has been found. If you have a counterexample please provide it. Merely juxtaposing two unrelated issues doesn't actually consisting a logical argument, but this particular juxtaposition is poorly chosen for your purpose. The 640k mistake was recognized and addressed within a few years. The lack of a listen backlog API has never been addressed at all, which shows that generations of TCP/IP implementors agree with me.
    – user207421
    Jan 27, 2017 at 21:35
  • Error messaging to the operator is one reason. Showing that the backlog is being hit is another, for exposing load status.
    – aredridel
    Nov 28, 2017 at 18:36
  • If any of these downvoters would care to tell us what they think the name of this non-existent API is, it would be most entertaining.
    – user207421
    Apr 30, 2018 at 22:13
  • 1
    @aredridel The question is about 'the backlg value that was set in the lsten() call', not about its current occupancy, and it's hard to see what they operator can do with, or about, that information.
    – user207421
    Apr 30, 2018 at 22:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.