Expert Articles

Magento ECG Expert Articles

Magento's Expert Consulting Group (ECG) is at the forefront of eCommerce innovation. Our premier experts have vast experience working with top merchants globally, and we will continuously publish articles on topics that are important for technologists working with Magento.

Powering Magento with Ngnix and PHP-FPM

By: Yuri Golovko and Alexey Samorukov | June 12th, 2015

When dealing with many simultaneous HTTP/HTTPS connections, Apache uses a high amount

of RAM and CPU cycles--especially when talking about a standard Apache configuration with the

mod_php prefork. In general, each Apache child process consumes around 100MB of RAM on each

request within a typical Magento installation. (To be clear, only resident memory is included in this

statistic, minus shared RAM.) On average, a dedicated web server with 16GB of RAM can handle no

more than roughly 150 concurrent requests.

The major difference between Nginx and Apache is that Apache is process-based while nginx is

event-based. Because Nginx is event-based it doesn’t need to spawn new processes or threads

to increase its level of concurrency, so its memory footprint is very low. Nginx also exploits nonblocking,

asynchronous I/O. Socket() and setsockopt() calls return results without blocking,

whereas connect(), send(), recv() and close() may experience some blockage at times. Nginx calls

the preceding functions only after confirming there will be no lag. To prevent blockage, for connect()

as an example, the socket is changed in advance to a non-blocking socket using ioctl(). As for send()

and recv(), epoll is used to prevent blockage. Codes for calling send() or recv() are composed in an

event-driven format. Each event is composed of a socket, a socket state, and an operating function.

Nginx is operated by a pre-set number of worker processes. Each process operates as a single

isolated process. Ngnix’s non-blocking, event-driven architecture allows a single worker process to

handle requests by multiple clients.

Download the article to the right to learn more about how using Ngnix and PHP-FPM can help.