Possible memory leak?
anoopalias01 at gmail.com
Fri Mar 8 03:08:32 UTC 2019
Its simple..Nginx has a master process and number of worker process as you
configure in nginx.conf . Its the workers that handle connections and each
one does async
When you do a HUP, all the master process is doing is spawning n new
workers and all new connections to port 80/443 are handled by the new
workers, but remember that he old workers may still be doing some job and
terminating it then and there means you are closing off some connections in
a non-graceful way, so the master process keeps the old workers also active
for sometime to let it gracefully finish all its doing
So if the worker process is n , during reload it will become 2n and then n
workers are gracefully shutdown which means if n workers use x memory ,
then during reload the memory become 2x
You can set workers to a low value ,say 1 worker process if the system is
limited in memory ,but the possibility of having 2n workers during reload
cannot be avoided as its more like a feature and the 2x memory usage is an
unwanted side effect of this feature
Having said that Nginx dev's can still look into why defining more vhost
consume lot of memory while apache dont have this problem. I develop an
automation script for a popular web control panel and most servers using
the script have upto 10k vhost defined and the memory usage would be 4x
times than apache for nginx with this much amount of vhosts defined . with
ssl defs etc needed for each vhost we cannot reduce the number of
On Fri, Mar 8, 2019 at 8:05 AM wkbrad <nginx-forum at forum.nginx.org> wrote:
> Thanks, Anoop! But I don't think you understood the point I was trying to
> get across. I was definitely not trying to compare nginx and apache memory
> usage. Let's just ignore that part was ever said. :)
> I'm trying to understand why Nginx is using 2x the memory usage when the
> signal is sent, i.e. the normal reload process.
> When you use the USR2/QUIT method, i.e. the binary upgrade process, it
> doesn't do this.
> It's a big problem on high vhost servers when you go from normally using 1G
> of ram to using 2G and then 4G during subsequent reloads.
> It's that brief 4G spike that initially caught my attention. But then I
> noticed that it was always using 2x more ram. Whoa!
> This is super easy to reproduce so I invite you to test it yourself.
> Posted at Nginx Forum:
> nginx mailing list
> nginx at nginx.org
*Anoop P Alias*
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the nginx