If you are still into Apache vs Nginx comparison, this article may help make up your mind and give a bit broader look at Nginx.

For quite a long time we had been using Apache as a default web server and Nginx only for high load projects until one day Apache went down with only 300 users.

That situation and further experience with Nginx shifted our perception of it as a server suitable only for high loads to a server that is just better for almost any project.

Having worked with Nginx for a few years already, we’ve seen its advantages in projects of various scales, even very small.

However, we've noticed that many of our American clients still stick to Apache. It happens, either because they don't think that other web servers will make a difference or don't know a better alternative.

Knowing the pros and cons of both technologies, we truly believe that Nginx is the best option in most cases and we’ll show you why.

The Best Web Servers

First, let's recap what these web servers are about and what's the difference between them.

Apache and Nginx, followed by Cloudflare Server, LiteSpeed, and Microsoft IIS, are the industry leaders of the web server software market.

But w3techs latest research shows that Nginx ratings are steadily going up, getting closer to leave Apache behind:

web servers diagram

Apache: Why Choose?

Apache logo

Apache is the market veteran with the market share (32%). It has been in use since 1995 and backed up by a rather solid company. This technology played a key role in the initial growth of the World Wide Web, quickly overtaking NCSA HTTPd as the dominant HTTP server, and has remained most popular since April 1996. In 2009, it became the first web server software to serve more than 100 million websites.

All this time the webserver has been developing in terms of features, community, and documentation. Lots of new modules have been created to considerably extend their functionality.

Despite Apache’s solidity and trustworthiness, it does not handle high traffic loads very well. This is caused by the very principle of its work, i.e. spawning new processes, which leads to consuming more computer memory. Furthermore, it creates new threads that must compete with others for access to memory and CPU. Apache will also refuse new connections when traffic reaches the limit of processes configured by the administrator.

Nginx: Why Choose?

Nginx logo

In comparison to Apache, Nginx has an almost equal market share (34%), it has been growing at lightning speed in the last couple of years. Since 2012 Nginx has gained 20%, while Apache has lost more than 25% of its market share in the same time period.

This web server is also relatively young. Russian programmer, Igor Sysoev, began working on it in 2002 and released the first version in 2004. Igor conceived the idea while working at Rambler, a leading Russian search engine at the time. Therefore, Nginx was born as a result of Igor's searchings to improve Rambler's performance under high load. In other words, it is his answer to the C10K problem - how to get one webserver to handle 10,000 connections per second, given the limitations of the operating systems.

As it says on Nginx’s website: “...performance is perhaps the single biggest driver of Nginx adoption”. According to W3Techs, top-rated websites use Nginx (45%):

  • 360.cn
  • Jd.com
  • Sina.com.cn
  • Zoom.us
  • Okezone.com
  • Microsoft.com

Nginx uses less memory than Apache and can handle roughly four times more requests per second. This is possible thanks to the way it operates - “event-driven and asynchronous”, which is very different from Apache. Nginx does not create new processes for each web request. The administrator configures how many worker processes to create for the main process and all of these processes are single-threaded. Each worker can handle thousands of concurrent connections. It does this asynchronously with one thread, rather than using multi-threaded programming.

It is also worth mentioning that sometimes both web servers are used at the same time - Nginx as a reverse proxy for Apache. In this combination, Nginx will take off most of the load from Apache. In our opinion, this can be an acceptable solution, if the system is already running with Apache and the costs of a full transfer to Nginx are greater, than using both in a combo.

You Don’t Need to Face a C10K Problem to Benefit from Nginx

The common misconception is that Nginx was invented for super high load websites, to solve ‘The C10K Problem', so its benefits cannot be felt in smaller projects.

Indeed, very few businesses and startups get to live up to the problem of handling 10 000 connections per second, so why bother looking for something better than Apache?

Even though your website might not experience the high load problem just yet, it still needs to be fast enough right from the start.

Yes, the webserver software is not the only factor that defines how fast your website or app will be. There are also issues of code quality and web server hardware.

However, altering code in the first stages of your project may lead to premature optimization. And you probably already know that premature optimization is the root of all evil. By optimizing software too early you risk wasting resources on a project that has not been properly tested in the field and there is a great likelihood it will require a lot of feature changes.

At the same time, upgrading hardware for the sake of performance may lead to increased expenses, especially in the long run.

Our experience tells us that in most instances it is much easier to satisfy Google Page Speed requirements with Nginx, than Apache.

page speed insights

To illustrate the Apache vs Nginx performance differences, we ran a test on one of our websites. We used the ‘ab’ server benchmarking tool to compare both web servers under two loads: 100 and 1000 simultaneous connections.

Apache vs Nginx Benchmark
Concurrency Level and Complete Requests Connection time, median to max for Apache (ms) Connection time, median to max for Nginx (ms)
100 and 1 000 35-52 15-23
1 000 and 10 000 46-52 336 61-1 423

code

This test shows that Nginx is indeed a lot faster. However, with Apache, your users won't experience real problems at the level of 100 simultaneous connections, but some of them will at the concurrency level of 1 000. With this amount of simultaneous connections, the page load time will be unacceptable for some of the users.

Notably, we conducted this test with both web servers as is, without special tuning and optimizing.

The Story of Apache Going Down at 300 User Load

A few years ago we were working on a custom web app that our client was going to use for a business conference. This was an Educational Game for an interactive workshop, where a trainer had to moderate the game on his laptop, and trainees (300 in total) had to play on individual iPads.

We’ve developed the web app with the following technologies: LAMP (with an ‘A’ for Apache), Yii, HTML, JavaScript, etc. Back then we were using Apache most of the time and Nginx only for high user loads. And we didn’t expect this project to go under the ‘high load’ category.

online game

However, it turned out that it did. When we started testing this app, we quickly saw that at times those 300 connections happened at the same fracture of a second, thus causing a peak load for the server. This happened due to the fact that the moderator had an option to switch slides for all players, so each of the 300 user clients would send requests to the server literary at the same time.

This caused Apache to consume all the memory and go down even with as few as 300 users.

At that time, we were able to fix it by adding VPS memory and reconfiguring the webserver.

Later on, we’ve tried out Nginx on similar projects, with 300 concurrency levels, and on more advanced projects with 1 000 and more connections. It worked every time! Even without reconfiguring and upgrades.

That’s when we decided to switch to Nginx for most of our projects, regardless of the user load. Now, we use Apache only in very rare cases, when we have to work on projects that have already been developed with this server technology by other teams.

Conclusion

Even though Apache has been the number one choice in web servers for years, now it is losing its position to the new rival. Nginx by far out beats Apache in making websites faster and handling high loads.

Not every project we work on comes with a high load challenge, however, we use Nginx most of the time anyway. It allows us to faster meet the Google Page Speed requirements without additional configurations and upgrades. And Nginx makes us prepared for when our websites do encounter peak traffic. Throughout dozens of projects, we cannot name any disadvantages to it.


Get a cost estimate for your custom website!

Contact Us




Authors

Kateryna Reshetilo

Kateryna’s job is to understand the markets the company is serving, formulate the best offerings for potential clients, and market them in the most effective way. In addition to that, she is also responsible for discovering new market niches and developing competitive strategies to exploit them.

Read More
Sergii Opanasenko

Sergii is responsible for establishing and overseeing the main business operations at Greenice. In particular, he supervises web development, QA, project management, HR, and sales. Sergii’s job is to ensure that all puzzle pieces of the business come together to provide the best service to our clients.

Read More

Rate this article!

You should be logged in to be able to rate articles

5

rating 1 rating 1 rating 1 rating 1 rating 1

Comments (0)

Login to live the comment