Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Your server socket listen backlog is limited to 100 connections

I run a flask app on uwsgi. I use supervisor to manage uwsgi process. I find the log saying that

your server socket listen backlog is limited to 100 connections.

How to overcome 100 connections limitation? My running script is as below:

[program:myapp]
command=uwsgi --master -s /tmp/app.sock --module myapp:app --processes 2 -H /srv/sites/mysite chmod-socket 666 --enable-threads
like image 495
shoujs Avatar asked Sep 09 '12 14:09

shoujs


People also ask

What is backlog in socket listen?

Listen causes a connection-oriented Socket to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance. To determine the maximum number of connections you can specify, retrieve the MaxConnections value.

What is backlog in networking?

In simple words, the backlog parameter specifies the number of pending connections the queue will hold. When multiple clients connect to the server, the server then holds the incoming requests in a queue.

How do I listen to a socket in C#?

In socket communication, one node acts as a listener and other node acts as a client. The listener node opens itself upon a pre-established IP address and on a predefined protocol and starts listening. Clients who want to send messages to the server start broadcasting messages on the same IP address and same protocol.

How does the server listen to incoming requests?

A server has a bind() method which binds it to a specific IP and port so that it can listen to incoming requests on that IP and port. A server has a listen() method which puts the server into listen mode. This allows the server to listen to incoming connections.


4 Answers

Note that a "listen backlog" of 100 connections doesn't mean that your server can only handle 100 simultaneous (or total) connections - this is instead dependent on the number of configured processes or threads. The listen backlog is a socket setting telling the kernel how to limit the number of outstanding (as yet unaccapted) connections in the listen queue of a listening socket. If the number of pending connections exceeds the specified size, new ones are automatically rejected. A functioning server regularly servicing its connections should not require a large backlog size.

According to the manual, you can change the listen backlog with the -l option:

-l|--listen <num>
       set  socket  listen queue to <n> (default 100, maximum is system
       dependent)
like image 151
user4815162342 Avatar answered Oct 12 '22 05:10

user4815162342


Simply increasing the uwsgi's listen backlog using the -l or --listen option (as pointed by user4815162342) while starting the server, to a value greater than 128 might stop uwsgi from starting up. There is also a system level limit on Unix socket and TCP connection listen queue, whose default is 128, that needs to be increased.

You can verify that setting like this:

cat /proc/sys/net/core/somaxconn

uwsgi has been patched such that if the value passed to --listen parameter while starting uwsgi is greater than the system level limit, it'll cause uwsgi to fail hard. If you want set uwsgi's listen queue limit greater than the system level limit, you must first increase the kernel's limit. That can be done executing the following commands:

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

Or

$ sysctl -w net.core.somaxconn=4096

Or, add net.core.somaxconn=4096 to /etc/sysctl.conf for it to persist through a reboot.

like image 21
Nabeel Ahmed Avatar answered Oct 12 '22 04:10

Nabeel Ahmed


As it was described in previous answers:

  1. Increase connections in kernel
  2. Increase connections in uWSGI too

Example. If you are using docker and docker-compose.

  1. How to increase connections in kernel

In docker-compose.yml, in block where you describe how to run uWSGI:

uwsgi_runner:
    <<: *app-base
    command: /usr/local/bin/uwsgi --ini /app/uwsgi.ini
    # ... other settings ...
    sysctls:
        net.core.somaxconn: 1024 # set max connections to 1024 in kernel
  1. How to increase connections in uWSGI

In uwsgi.ini:

[uwsgi]
# ... other settings ...
listen = 1024 # set max connections to 1024 in uWSGI

Also, you can change this parameter directly in docker-compose command (-l or --listen flag) if you are not using uwsgi.ini settings file:

uwsgi_runner:
    <<: *app-base
    command: /usr/local/bin/uwsgi -l 1024 #other-parameters-here
like image 37
Denis Krumko Avatar answered Oct 12 '22 05:10

Denis Krumko


You can modify SOMAXCONN in your /proc/sys/net/core/somaxconn to increase this limit.

It's simply linux tuning systems.

like image 42
Lujeni Avatar answered Oct 12 '22 04:10

Lujeni