Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Which engines are apache-HTTP and Nginx are stronger?


Jun 01, 2021 Article blog


Table of contents


This article describes the two Apache-HTTP and Nginx respectively, and then compares their differences. Any shortcomings are welcome to be added.

HTTP middleware

When we enter a link to a web page in the browser, the browser sends a request to the corresponding server based on HTTP(s) transport protocol, the server receives the corresponding request and processes it, returns the corresponding information to the browser, and then the browser parses the content in http which manifests itself as a web page.

The server is responsible for receiving the request and returning the appropriate data after processing, which can be broken down into the service portion that handles http connection and the app portion that executes the service content WordPress uses PHP to generate the required pages, which belongs to the app section)

Regardless of what application the app section performs, the part that http connection is almost identical, so middleware has emerged that specializes in http connections, most commonly Apache and Nginx

Apache

Officially known as Apache HTTP Server it is an open source HTTP server middleware that was born in 1995 and was once the leader in HTTP services, with a large number of users and rich community resources. One of Apache great advantages is its ease of integration with CMS software such as Wordpress which requires a simple setup to build a CMS-based website.

Apache's internal processing model

Internally, Apache takes a multi-process approach, opening up a process for each connection, specifically for processing requests on that connection until the connection ends. The benefits of this are:

  • Connections from different clients are immediately appropriate and non-disturbing, and do not cause a service to take a long time to get its connections unresponsive.

But the disadvantages are also obvious:

  • When the number of simultaneous visits is high, Apache builds a large number of processes and consumes too much memory resources.
  • Scheduling between large numbers of threads can also result in a significant waste of CPU processing power.

This creates a challenge known as C10K which is client, and 10K means 10,000, meaning Apache struggles to process more than 10,000 connections at the same time, regardless of server performance and network bandwidth.

Nginx

Read Engine-X like Apache is an open source middleware for HTTP services, born in 2004. Nginx has a shorter history than Apache but because it's a latecomer, Nginx learned the lessons of Apache taking into account efficiency issues when dealing with large numbers of connections early in its design, and solving challenges such as C10K as the Internet grew in size.

Nginx's internal processing model

Nginx takes a 非阻塞IO and asynchronous message-driven approach, where loops are used in worker called workers to process connection requests in queues. Depending on the hardware, multiple worker can be set up to take full advantage of the CPU core resources.

  • Solves the problem of consuming too much memory and inefficient scheduling when dealing with a large number of connections, while making full use of all CPU cores. The ability to handle concurrent connections with the same hardware is 10 to 100 times greater than Apache

But Nginx is not without its drawbacks.

  • When server single-core performance is poor, CMS-based dynamic sites may take a long time to execute a request, at which point requests from other clients will not be executed immediately. This is more noticeable when there are fewer CPU cores and there are not enough worker threads.

Fortunately, server performance is getting stronger, the number of CPU cores is increasing under AMD Nginx shortcomings are enough to compensate, and the benefits of efficiency are becoming more apparent.

Comprehensive comparison

Apache Nginx has limited processing power 10-100 times whether it will be blocked by complex tasks whether it is possible to set the difficulty is relatively simple relatively complex community resources are relatively small

In recent years, Nginx market share has continued to grow, reaching the same level as Apache in 2019. F or large sites with a lot of traffic, you can see that the greater the traffic, the higher the proportion of Nginx This also confirms from the side the superior performance of Nginx when dealing with a large number of visits.

 Which engines are apache-HTTP and Nginx are stronger?1

Load balancing

In addition to being available as an HTTP server, Nginx powerful reverse proxy capabilities are widely used as load balancing front-end servers, gradually replacing hardware-based load balancers.

Several back-end servers can be configured in Nginx which forwards requests to back-end servers according to certain rules (polling, IP hashing, priority randomness) after receiving HTTP requests, and so on, achieving an average or weighted distribution of load on multiple servers. Nginx

It also caches data returned by the back end as a load-balanced front end, easing the pressure on the back-end server. The front end uses Nginx to do load balancing to limit the number of connections per server, and it is not uncommon for back-end servers to run Apache

F5 networks the industry boss of hardware load balancers, acquired Nginx in 2019 and launched Nginx+ a load balancing solution that includes paid services.

The above is about the comparison between apache and nginx hoping to help people who are new to apahce and nginx U sing a product can't be confusing, we need to understand its advantages and disadvantages in order to use them better. You can also learn more about it

Nginx Getting Started Guide: https://www.w3cschool.cn/nginx/