[Nginx] Advantages and Disadvantages of nginx and Apache

Source: Internet
Author: User
Tags epoll

Refer:

Http://zyan.cc/nginx_php_v6/

Advantages of nginx over Apache:
1. lightweight and similar web services, which consume less memory and resources than Apache servers
2. Anti-concurrency. nginx processes Requests asynchronously and non-blocking (epoll), while Apache is blocking (select). In high concurrency, nginx can maintain low resource consumption and high performance.
3. highly modular design, relatively simple Writing module

4. Apache is a synchronous multi-process model. One connection corresponds to one process. nginx is asynchronous. Multiple connections (tens of thousands of connections) can correspond to one process.

Advantages of Apache over nginx:
1. nginx is used to process dynamic requests. Generally, dynamic requests must be processed by Apache. nginx is only applicable to static and reverse requests.

2. Apache provides simple support for PHP. nginx must be used with other backend servers.

-----------------------------------------------------------

Whether it is nginx or squid reverse proxy, its network mode is event-driven. Event-driven is actually a very old technology, as did select and poll in the early stages. Later, more advanced event Mechanisms Based on Kernel notifications emerged, such as epoll in libevent, which improved the event-driven performance. The essence of event-driven is Io events. Applications can quickly switch between multiple Io handles to Implement Asynchronous Io. The event-driven server is most suitable for IO-intensive work, such as reverse proxy, which acts as a data transit between the client and the web server, purely Io operations, it does not involve complex computing. The reverse proxy uses the event-driven method. Obviously, it is better to run a working process without the overhead of process and thread management, and the CPU and memory consumption are low.

Nginx works well in processing static files, because static files are also disk I/O operations, and the processing process is the same.

Application servers such as Apache and resin are called Application Servers because they really need to run specific business applications, such as scientific computing, graphic images, and database read/write. They are probably CPU-intensive services and event-driven services are not suitable. For example, if a computing task takes 2 seconds, the two seconds are completely blocked and no event is used. Think about what happens if MySQL is changed to an event-driven one. A large join or sort will block all clients. At this time, multiple processes or threads show their advantages. Each process does everything and does not block or interfere with each other. Of course, the modern CPU is getting faster and faster, and the blocking time of a single computing may be very small, but as long as there is blocking, event programming has no advantage. Therefore, the process and thread technologies will not disappear, but will complement the event mechanism for a long time.

To sum up, event drivers are suitable for IO-intensive services, while multiple processes or threads are suitable for CPU-intensive services. They have their own advantages and there is no tendency to replace others.

 

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.