Why Nginx Beats Apache in High‑Concurrency Environments

This article explains why Nginx outperforms Apache under heavy load by comparing their architectures, work modes, memory usage, event‑driven design, and scalability techniques, and shows how Nginx can handle tens of thousands of concurrent connections with far less resources.

Open Source Linux
Open Source Linux
Open Source Linux
Why Nginx Beats Apache in High‑Concurrency Environments
Why is Nginx superior to httpd (Apache) when handling high concurrency? We start by examining the operating principles and models of the two web servers.

Nginx has quickly become a dominant web server, especially efficient for serving static content under massive concurrent requests, easily solving the C10K problem.

In high‑concurrency scenarios, Nginx is a solid replacement for Apache and can also serve as a Layer‑7 load balancer. Tests show Nginx + PHP(FastCGI) handling over 30,000 concurrent connections—about ten times what Apache achieves in a comparable environment.

On a 4 GB server, Apache in prefork mode manages roughly 3,000 concurrent connections, consuming over 3 GB of memory and often exhausting system resources. In contrast, an Nginx + PHP(FastCGI) setup with 30,000 connections uses only about 150 MB for ten Nginx processes ( 15M*10=150M) and 1,280 MB for 64 php‑cgi processes ( 20M*64=1280M), staying under 2 GB total.

Even at 30,000 concurrent connections, PHP scripts served by Nginx + FastCGI remain fast.

1. Apache’s Three Work Modes

Apache provides three Multi‑Processing Modules (MPMs): prefork, worker, and event.

prefork: multiple processes, each handling one request using the select mechanism.

worker: multiple threads per process, each thread handling a request while still using select.

event: asynchronous I/O model where a single process or thread handles many requests via epoll‑based event notification.

1) prefork

When no explicit MPM is specified, prefork is the default on Unix. It spawns child processes in advance, a model inherited from Apache 1.3, and does not use threads, offering high stability.

2) worker

Worker combines multiple processes with multithreading, allowing a larger number of requests with lower resource overhead than pure process‑based servers, while retaining Apache’s stability.

3) event

The event MPM uses a single process to handle many connections via epoll, keeping the process idle when no work is pending and thus supporting massive concurrency with minimal resource consumption.

2. Improving Web Server Concurrency

Key factors include:

Thread‑based models: one process creates many threads, each serving a request.

Event‑driven models: a single process handles multiple requests using epoll for readiness notifications.

Asynchronous I/O (AIO) on disk.

Memory‑mapped I/O (mmap) to avoid redundant copying of page data.

Nginx supports all these features, which is why its documentation claims support for 50,000 concurrent connections.

3. What Makes Nginx Exceptional

Traditional process‑ or thread‑based servers suffer from blocking I/O, low CPU/memory utilization, and costly context switches. Nginx adopts a modular, event‑driven, asynchronous, single‑threaded architecture that leverages epoll and multiplexing to handle thousands of connections per worker process efficiently.

4. Nginx Architecture

Nginx runs a master process and several worker processes (plus optional cache loader/manager processes). Each process contains only one thread and communicates via shared memory. The master runs as root, while workers run with non‑privileged users.

Its simple configuration, low bug count, and ability to run continuously for months without restart make Nginx ideal for 24/7 services and seamless upgrades.

5. Nginx’s Origin: Solving the C10K Problem

Comparison of I/O multiplexing models:

select : limited file descriptor count, linear scanning overhead.

poll : removes descriptor limit but still scans linearly.

epoll (used by Nginx): event‑driven readiness notification, returns only the number of ready descriptors, uses mmap to avoid copying large descriptor tables, and provides superior performance on Linux 2.6+.

epoll’s limitation is that it is Linux‑only, whereas Apache remains cross‑platform.

Source: http://codebay.cn/post/8557.html
This concludes the discussion on why Nginx is more powerful than Apache. For more related content, search "Open Source Linux" on WeChat or explore the articles below.

神器 Nginx 的学习手册

Nginx流控

Nginx 配置文件详解

Nginx 五大常见应用场景

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

high concurrencyNginxWeb serverApacheEvent-driven
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.