Home  >  Q&A  >  body text

Ab throughput test, why nginx is not as good as apache

environment

系统 win7 x64 8G内存 ADM7750双核
对比 
1) Apache 2.4.9 + php5.5.12 ts vc11 
2) NGINX 1.6.2 + PHP-FPM

Code

<?php 
# http://localhost/hello.php
echo  "hello";
<!-- http://localhost/js.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
</body></html>

test

./ab -c10 -n1000 http://localhost/hello.php
./ab -c10 -n1000 http://localhost/js.html

result

            js.html                         hello.php
nginx      0.907sec 1102/sec                timeout error 
apache     0.695sec 1439/sec                0.198s 1089/sec

doubt

Now everyone recommends nginx, but why is the throughput of nginx no matter pure HTML or PHP alone, not as good as Apache
UGC platform is more suitable for Apache or nginx?

怪我咯怪我咯2713 days ago838

reply all(5)I'll reply

  • 漂亮男人

    漂亮男人2017-05-16 17:03:44

    IIS and Apache performance comparison test on Windows 7
    IIS + php-cgi.exe(NTS) vs Apache + php5apache2_4.dll(TS)
    Environment (64-bit Win7): IIS7+PHP5.4 (NTS non-thread-safe version) vs Apache2.4 (32-bit)+PHP5.4
    Static file performance:

    ab -k -c100 -n10000 http://127.0.0.1/info.htm      # IIS RPS 1709
    ab -k -c100 -n10000 http://127.0.0.1:8080/info.htm # Apache RPS 1847
    

    Conclusion: Apache based on APR runtime and WinNT multi-threading is no worse than IIS in static resource processing.

    PHP Performance:

    ab -k -c100 -n10000 http://127.0.0.1/bs.php      # IIS RPS 1180
    ab -k -c100 -n10000 http://127.0.0.1:8080/bs.php # Apache RPS 1071
    

    Conclusion: Apache uses threaded MPM, so it needs to use a thread-safe version of PHP. The thread-safety check has a certain overhead, so the performance is lower than IIS+PHP-CGI.

    Nginx is not based on multi-threading to achieve high concurrency, but is based on epoll (Linux), kqueue (FreeBSD) event-driven asynchronous network IO mechanism. Nginx uses the most original select on Windows, not Windows IOCP, so Windows This version of Nginx is only targeted at testing and development. To unleash the true performance of Nginx, it must be on Linux or FreeBSD.

    Although Apache also uses select system calls on Windows, Apache's WINNT MPM is a multi-threaded MPM, so it even has advantages over IIS in processing static resources under non-high concurrency (such as 100 concurrency). In addition, Apache also has MPM that uses epoll on Linux. For example, the default event MPM in the 2.4 series is an epoll event-driven architecture. The main process manages multiple worker processes, and each worker process has multiple threads. Using epoll Performing asynchronous network IO is Apache’s powerful response to the challenge of Nginx.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 17:03:44

    windows doesn’t explain anything. It is only used for testing under windows and nothing more.
    Version of nginx for Windows uses the native Win32 API (not the Cygwin emulation layer). Only the select() connection processing method is currently used, so high performance and scalability should not be expected. Due to this and some other known issues version of nginx for Windows is considered to be a beta version.
    Windows does not have epoll and kqueue, so nginx naturally performs poorly when using select on Windows.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 17:03:44

    It is a good habit for the poster to personally test and verify, but Linux is generally used as the nginx server. If you use windows, the performance of nginx may not be as good as apache. It should be that both nginx and apache use the same operating mechanism select on windows, which is similar to queuing loop processing.
    The slow performance of nginx under windows may be due to: nginx also needs to call php-cgi, and apache has built-in integration of php's sapi.

    Under Linux, apache is still the choice, and nginx can use epoll, then:
    apache still queues up for processing
    nginx’s epoll mechanism, comes a request, throws it to php-cgi, and then proceeds to the next request. When php-cgi is finished processing, just return it to the client. This goes in parallel.

    The poster can take a look at the difference between epoll and apache:
    Suppose you are studying in college and the dormitory building you live in has many rooms, and your friends want to come to you.

    The hostess in the select version will take your friends to look for you from room to room until they find you.

    The epoll version of the dormitory aunt will first write down the room number of each student. When your friend comes, you only need to tell your friend which room you live in. You don’t have to take your friend around the building to find someone.

    If 10,000 people come and want to find their classmates who live in this building, it is self-evident who is more efficient in the select version or the epoll version.

    Similarly, in high-concurrency servers, polling I/O is one of the most time-consuming operations. It is also very clear which performance is higher between select and epoll.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 17:03:44

    Win NG? 哎

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 17:03:44

    I won’t post the configuration. Has nginx enabled epool?

    reply
    0
  • Cancelreply