Welcome! Log In Create A New Profile

Advanced

Re: worker_connections allocates a lot of memory

Maxim Dounin
June 16, 2020 06:22PM
Hello!

On Tue, Jun 16, 2020 at 03:42:04AM -0400, shaharmor wrote:

> I noticed that worker_connections while is defined as the maximum number of
> connections per worker, nginx pre-allocated enough memory to handle all
> possible worker_connections, even before they are actually needed.
>
> For example, setting worker_connections to 10485760 causes nginx to take
> 4.3GB of memory upon init.
>
> Is this how its supposed to be?

Yes.

> Is there a way to tell nginx to only allocate memory as needed?

No.

Connection structures are small and cannot be freed, so nginx
allocates them all on startup. This way it avoids memory
fragmentation, and makes connnection management easier and faster.

Note well that you cannot really use connection structures in
nginx without corresponding kernel structures such as sockets and
appropriate buffers, so using arbitrary large worker_connections
value does not make sense. If you are seeing that it takes
significant amount of memory, most likely you've configured it
incorrectly.

For example, some relevant numbers can be seen in the following
blog post by WhatsApp:

https://blog.whatsapp.com/1-million-is-so-2011

Numbers in suggest that about 64G of memory is needed to handle 2
millions of connections. Scaling this to 10 millions as in your
example gives about 256G, so 4G for worker_connections shouldn't
be noticeable.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

worker_connections allocates a lot of memory

shaharmor June 16, 2020 03:42AM

Re: worker_connections allocates a lot of memory

Marcin Wanat June 16, 2020 04:34AM

Re: worker_connections allocates a lot of memory

Maxim Dounin June 16, 2020 06:22PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 62
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready