Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backlog value in listen system call

Tags:

c

linux

sockets

I have a doubt regarding the backlog value in listen system call. From man page of listen system call.

If the backlog argument is greater than the value in /proc/sys/net/core/somaxconn, then it is silently truncated to that value; the default value in this file is 128.

It means my server can accept only <128 connections at once. What if I want to accept more connection >128 ?? Can I simply set the value to the possible maximum number so that I can access more number of connection ??

like image 625
codingfreak Avatar asked Oct 28 '09 07:10

codingfreak


People also ask

What is backlog in Listen function?

backlog. Defines the maximum length for the queue of pending connections. The listen() call indicates a readiness to accept client connection requests. It transforms an active socket into a passive socket. Once called, socket can never be used as an active socket to initiate connection requests.

What is the use of listen () system call?

The listen() system call prepares a connection-oriented server to accept client connections. The first parameter is the socket descriptor from the socket() call, sockfd. The second parameter specifies the number of requests that the system queues before it executes the accept() system call.

How the Listen function maintains the request in queue?

If a connection request arrives before the server can process it, the request is queued until the server is ready. When you call listen, you inform TCP/IP that you intend to be a server and accept incoming requests from the IP network. By doing so, socket status is changed from active status to passive.

What is the purpose of listen function call in TCP IP client/server communication?

The listen function converts an unconnected socket into a passive socket, indicating that the kernel should accept incoming connection requests directed to this socket. In terms of the TCP state transition diagram (Figure 2.4), the call to listen moves the socket from the CLOSED state to the LISTEN state.


3 Answers

That number is only the size of the connection queue, where new connections wait for somebody to accept them. As soon as your application calls accept(), a waiting connection is removed from that queue. So, you can definitely handle more than 128 simultaneous connections because they usually only spend a short time in the queue.

like image 60
Greg Hewgill Avatar answered Oct 20 '22 00:10

Greg Hewgill


Yes. Use a command such as

$ echo 1000 >/proc/sys/net/core/somaxconn

To set the limit higher. See, for instance, this page for more tuning tips.

like image 32
unwind Avatar answered Oct 20 '22 01:10

unwind


The backlog value is not the number of maximum connections, it's the number of outstanding connections, i.e connections which you havn't accept():ed.

like image 25
Puppe Avatar answered Oct 20 '22 00:10

Puppe