Understanding Nginx Performance

Nginx is a tiny web server that features high concurrency support and multi-functionality.

Nginx Market Share

Its continually increasing market share tells you it may be a good choice to switch to Nginx. Apache and Windows Server are losing market while Nginx keeps gaining more. Nginx is currently the second most widely used web server for top million busiest sites according to netcraft (https://news.netcraft.com/archives/2017/01/12/january-2017-web-server-survey.html).

Nginx Limitation

However, Nginx may not always better than Apache in speed. That’s because Nginx is itself a static resource web server. It uses IO multiplexing system call provided by Linux to manage concurrent HTTP connections. Epoll , an O(1) time algorithm, is actually used as long as Linux supports it (http://nginx.org/en/docs/events.html) . Apache uses select, an O(n) time algorithm.

Nginx Applications

  1. Web server (multiple hosts)
  2. Load balancer (reverse proxy)
  3. Web cache (local cache in front of static resources storage)

Nginx Advantage

  1. High concurrency for small static resources. (10k to 20k concurrent connections)
  2. Low memory cost. (less than 1GB for 20k concurrent connections)
  3. Many applications, but not very strong for each one
  4. Support Epoll model, which increases high concurrency
  5. Collaboration with dynamic services.
  6. Limit speed based on IP; limit connections.
  7. Easy and flexible configuration.