<div dir="ltr">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<div><br></div><div>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 </div><div><br></div><div>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 </div><div><br></div><div>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</div><div><br></div><div>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 vhosts also <br><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 8, 2019 at 8:05 AM wkbrad <<a href="mailto:nginx-forum@forum.nginx.org">nginx-forum@forum.nginx.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks, Anoop!  But I don't think you understood the point I was trying to<br>
get across.  I was definitely not trying to compare nginx and apache memory<br>
usage. Let's just ignore that part was ever said.  :)<br>
<br>
I'm trying to understand why Nginx is using 2x the memory usage when the HUP<br>
signal is sent, i.e. the normal reload process.<br>
<br>
When you use the USR2/QUIT method, i.e. the binary upgrade process, it<br>
doesn't do this.<br>
<br>
It's a big problem on high vhost servers when you go from normally using 1G<br>
of ram to using 2G and then 4G during subsequent reloads.<br>
<br>
It's that brief 4G spike that initially caught my attention.  But then I<br>
noticed that it was always using 2x more ram.  Whoa!<br>
<br>
This is super easy to reproduce so I invite you to test it yourself.<br>
<br>
Posted at Nginx Forum: <a href="https://forum.nginx.org/read.php?2,283216,283312#msg-283312" rel="noreferrer" target="_blank">https://forum.nginx.org/read.php?2,283216,283312#msg-283312</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b>Anoop P Alias</b> <div><br></div></div></div></div>