Comparison of the advantages of Apache and Nginx

Source: Internet
Author: User

I've been told that Nginx is better than Apache and faster than Apache. Nginx is primarily used as a reverse proxy, not a Web server. I have translated a technical book about reverse proxy, and proficient in the development of Apache API, the working principle of nginx and Apache have a little understanding, rough talk about the view.

Whether it is nginx or squid, the reverse proxy, its network mode is event-driven. Event-driven is actually a very old technique, as was the case with the early select and poll. Later, more advanced event mechanisms based on kernel notifications, such as the Epoll in Libevent, have led to improved event-driven performance. The essence of event-driven is the IO event, where applications quickly switch between multiple IO handles to implement so-called asynchronous IO. Event-driven server, the best thing to do is this IO-intensive work, such as reverse proxy, it between the client and the Web server a data transfer function, purely IO operation (IO operation does not block the process), itself does not involve complex computing. Reverse proxy with event-driven to do, obviously better, a worker process can run, no process, thread management overhead, CPU, memory consumption is small.

So nginx, squid are doing so. Of course, Nginx can also be a multi-process + event-driven mode, a few processes run libevent, do not need Apache as much as hundreds of of the process number. Nginx processing static files is also good, because the static file itself is a disk IO operation, the same process. As for the number of concurrent connections, this is meaningless. I write a Web program that can handle tens of thousands of of concurrency, but if the majority of clients are stuck there, there is no value.

Look at Apache or resin applications such as server, they are called application servers, because they really want to run specific business applications, such as scientific computing, graphic images, database reading and writing. They are probably CPU-intensive services, and event-driven is not appropriate. For example, a computation takes 2 seconds, so 2 seconds is completely blocked and nothing is useless. Think about MySQL. If you change to an event driver, a large join or sort will block all clients. At this time the multi-process or the thread manifests the superiority, each process each individual matter, does not block and interferes. Of course, the modern CPUs are getting faster, and the time for a single computational blockage can be small, but as long as there is blocking, event programming has no advantage. So the process, threading technology, does not disappear, but with the event mechanism to complement, long-term existence.

In summary, event-driven is suitable for IO-intensive services, multi-process or thread-appropriate for CPU-intensive services, each with their own advantages, and there is no inclination to replace who. Again the blind words of the nginx can replace Apache, it should be a good reflection.


Comparison of the advantages of Apache and Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.