Forum: NGINX Memory Pool

2974d09ac2541e892966b762aad84943?d=identicon&s=25 nginxsantos (Guest)
on 2014-04-09 10:56
(Received via mailing list)
Nginx when it accepts a connection, it creates a memory pool for that
connection (allocating from heap). After which further memory
requirement
for that connection will be allocated from that pool. This is good.
But, why don't we pre create the memory pools depending upon the number
of
connections and use that pool. In the current approach if some
connections
are coming up going down., we will be allocating and freeing to heap
frequently.

Can someone please clarify why this has been done like this?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249144,249144#msg-249144
2974d09ac2541e892966b762aad84943?d=identicon&s=25 nginxsantos (Guest)
on 2014-04-09 11:46
(Received via mailing list)
Also I noticed that initially for a connection, it allocates a pool of
size
256 and if that exceeds, it goes and calls ngx_palloc_large which in
turn
calls malloc.

So, can we not allocate more in the first attempt.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249144,249149#msg-249149
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-04-09 12:25
(Received via mailing list)
On Wednesday 09 April 2014 04:55:42 nginxsantos wrote:
> Nginx when it accepts a connection, it creates a memory pool for that
> connection (allocating from heap). After which further memory requirement
> for that connection will be allocated from that pool. This is good.
> But, why don't we pre create the memory pools depending upon the number of
> connections and use that pool. In the current approach if some connections
> are coming up going down., we will be allocating and freeing to heap
> frequently.
>
> Can someone please clarify why this has been done like this?
>

System allocators are usually smart enough to not transform every
malloc()
into syscall.

One of the main benefits provided by these pools is convenient memory
management for C program that allows to not care much about
corresponding
free() calls and memory leaks.

So usually every pool is attached to some object with a clear life
cycle,
like a request or a connection.

  wbr, Valentin V. Bartenev
2974d09ac2541e892966b762aad84943?d=identicon&s=25 nginxsantos (Guest)
on 2014-04-09 14:22
(Received via mailing list)
Thank you for the reply.

I know it is simple. But, will we not get more performance benefit if we
create the pools before hand. Say I will create a memory pool for the
connections (for example say with 4000 entries). Everytime I need one, I
will go and get it from that pool and when I free it, I will free that
to
the pool. Will not that be more efficient rather than for every
connection
and request going and allocating a pool.

I always feel the run time malloc calls are bad and for every connection
and
request are expensive when we handle thousands of connections per
seconds.

Please share your thoughts....

Thank you.
Santos

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249144,249159#msg-249159
40b4c848b8fcd63b0cb60b9d170c3a77?d=identicon&s=25 Valentin V. Bartenev (Guest)
on 2014-04-09 16:10
(Received via mailing list)
On Wednesday 09 April 2014 08:22:10 nginxsantos wrote:
> request are expensive when we handle thousands of connections per seconds.
>
> Please share your thoughts....
>

I think performance benefits will be negligible.  There are lightweight
web
servers like Lighttpd that doesn't use memory pools and known to be
pretty
fast.

Also note, that allocation of connection pool is just a one small
allocation,
that nginx does during request processing among number of allocations of
various buffers.

  wbr, Valentin V. Bartenev
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.