Search This Blog

Friday, December 6, 2013

Tuning Nginx/CentOS for server lots of static content - Stack Overflow

Tuning Nginx/CentOS for server lots of static content - Stack Overflow:

One thing you should probably just do asap is to disable atime , mount your filesystem where the files reside on with the noatime option - this will reduce drive IO quite a bit - you likely don't need the access time of files to be updated –  nos Jan 29 '11 at 19:56 

I found this tutorial,… and I would have to add the noatime to /dev/sda5.

This site even talks about "nodiratime" too which means: Do not update directory inode access times on this filesystem…

Along with the noatime option @nos mentioned, you might want to consider the following:
  • in nginx, set access_log off; -- commenting it out doesn't do anything; you need to actively disable it.
  • reduce the number of worker processes. nginx doesn't benefit from more than one worker per CPU.
  • tcp_nodelay on; will help nginx serve files quicker on "live" connections.
  • try playing with tcp_nopush. I've found it best to switch it on, but YMMV.
  • set if_modified_since to before; it will allow nginx to send 304 Not Modified headers rather than re-serving the content.
  • play with the open_file_cache settings
  • reduce the send_timeout so nginx can free-up stale client connections.
As for the rest of your system:
  • hdparam settings. lots of tutorials to help you online, hdparam tweaks will get the best out of your disks.
  • tweak your socket performance settings
  • recompile the kernel with a reduced timer frequency. the default is 1000 Hertz which is great for desktop machines providing video but isn't all that good for servers where a value of 100-250 might be more appropriate
  • disable services like cups and bluetooth
However, I believe the best performance boost would be putting Varnish in front of your nginx server and using it rather than nginx for serving static files. It will keep "hot" files in memory better than nginx can, so that there's little/no disk use for your most-served content.
The main thing however is to monitor EVERYTHING -- don't go with your gut, know what your server is doing and where your bottlenecks are.

No comments:

Post a Comment