Сравнительное тестирование apache+mod_php VS nginx+php5_fpm на Zend Framework приложении
Сейчас рассматриваю варианты увеличения производительности Zend Framework веб-приложения. Один из вариантов – это перевод веб-серера с Apache + mod_php на Nginx + php5-fpm
Итак для просто ты сделал два теста.
Тесты
Первый (конкурентность 1):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
andrey@vaio:~$ <strong>ab -c 1 -n 10 http://site.new/ru/</strong> This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Server Software: <span style="text-decoration: underline;"><strong>Apache/2.2.14</strong></span> Server Hostname: site.new Server Port: 80 Document Path: /ru/ Document Length: 228538 bytes Concurrency Level: 1 Time taken for tests: 20.641 seconds Complete requests: 10 Failed requests: 7 (Connect: 0, Receive: 0, Length: 7, Exceptions: 0) Write errors: 0 Total transferred: 2287794 bytes HTML transferred: 2285384 bytes Requests per second: <strong><span style="text-decoration: underline;">0.48</span></strong> [#/sec] (mean) Time per request: 2064.055 [ms] (mean) Time per request: 2064.055 [ms] (mean, across all concurrent requests) Transfer rate: 108.24 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 0 Processing: 1869 2064 165.0 2027 2292 Waiting: 1825 2024 165.1 1989 2253 Total: 1869 2064 165.0 2027 2292 Percentage of the requests served within a certain time (ms) 50% <strong>2027</strong> 66% 2111 75% 2273 80% 2284 90% 2292 95% 2292 98% 2292 99% 2292 100% 2292 (longest request) |
А теперь nginx+php5_fpm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
ab -c 1 -n 10 http://site.new/ru/ Server Software: <strong><span style="text-decoration: underline;">nginx/0.7.65</span></strong> Server Hostname: site.new Server Port: 80 Document Path: /ru/ Document Length: 228245 bytes Concurrency Level: 1 Time taken for tests: 7.281 seconds Complete requests: 10 Failed requests: 0 Write errors: 0 Total transferred: 2284030 bytes HTML transferred: 2282450 bytes Requests per second: 1.37 [#/sec] (mean) Time per request: 728.104 [ms] (mean) Time per request: 728.104 [ms] (mean, across all concurrent requests) Transfer rate: 306.34 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 0 Processing: 668 728 31.6 721 777 Waiting: 661 720 31.4 714 769 Total: 669 728 31.6 721 777 Percentage of the requests served within a certain time (ms) 50% <span style="text-decoration: underline;"><strong>721</strong></span> 66% 722 75% 755 80% 769 90% 777 95% 777 98% 777 99% 777 100% 777 (longest request) |
Второй (конкурентность 5):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
andrey@vaio:~$ <strong><span style="text-decoration: underline;">ab -c 5 -n 10 http://site.new/ru/</span></strong> This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Server Software: <strong><span style="text-decoration: underline;">Apache/2.2.14</span></strong> Server Hostname: site.new Server Port: 80 Document Path: /ru/ Document Length: 228538 bytes Concurrency Level: 5 Time taken for tests: 12.106 seconds Complete requests: 10 Failed requests: 6 (Connect: 0, Receive: 0, Length: 6, Exceptions: 0) Write errors: 0 Total transferred: 2287716 bytes HTML transferred: 2285306 bytes Requests per second: <span style="text-decoration: underline;"><strong>0.83</strong></span> [#/sec] (mean) Time per request: 6053.053 [ms] (mean) Time per request: 1210.611 [ms] (mean, across all concurrent requests) Transfer rate: 184.54 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.4 0 1 Processing: 5005 5740 655.9 5447 6682 Waiting: 4889 5648 634.2 5404 6576 Total: 5005 5740 655.9 5448 6682 Percentage of the requests served within a certain time (ms) 50% <span style="text-decoration: underline;"><strong>5448</strong></span> 66% 5955 75% 6542 80% 6632 90% 6682 95% 6682 98% 6682 99% 6682 100% 6682 (longest request) andrey@vaio:~$ |
А теперь Nginx + php5_fpm:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
andrey@vaio:~$ <strong><span style="text-decoration: underline;">ab -c 5 -n 10 http://site.new/ru/</span></strong> This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Server Software: <span style="text-decoration: underline;"><strong>nginx/0.7.65</strong></span> Server Hostname: site.new Server Port: 80 Document Path: /ru/ Document Length: 228245 bytes Concurrency Level: 5 Time taken for tests: 4.227 seconds Complete requests: 10 Failed requests: 0 Write errors: 0 Total transferred: 2284030 bytes HTML transferred: 2282450 bytes Requests per second: <strong><span style="text-decoration: underline;">2.37</span></strong> [#/sec] (mean) Time per request: 2113.383 [ms] (mean) Time per request: 422.677 [ms] (mean, across all concurrent requests) Transfer rate: 527.71 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 4.2 0 13 Processing: 858 1647 974.3 1495 4223 Waiting: 837 1634 975.3 1485 4212 Total: 858 1649 974.9 1506 4227 Percentage of the requests served within a certain time (ms) 50% 1506 66% 1553 75% 1851 80% 1858 90% 4227 95% 4227 98% 4227 99% 4227 100% 4227 (longest request) andrey@vaio:~$ |
Выводы
Конкурентность = 1 Apache: 0,48 запроса в секунду, Nginx: 1,37 запросов в секунду. Время обработки запроса на Nginx: 0,7 сек
Конкурентность = 5 Apache: 0,83 запроса в секунду Nginx: 2,37 запроса в секунду. Время обработки запроса на Nginx: 1,2 сек
Дальше мерял только Nginx:
Конкурентность = 10 Nginx: 3,35 запроса в секунду. Время обработки запроса (среднее): 1,8 сек
Конкурентность = 50 Nginx: 3,41 запроса в секунду. Время обработки запроса (среднее): 14 сек
Получается ускорение на 35% при ч1ём оно судя по всему не зависит от конкурентности.
Также мне кажется, что прирост в общем-то произошел от перехода на nginx а не от php_fpm.
P.S. Если поменять взаимодействие с порта на cокеты, то производительности это не добавит.
Какой то показатель низкий.
2 секунды в первом тесте – это чистое приложение ZF, только что созданное с помощью Zend_Tool?
APC/eAccelerator – включен?
Добрый день, Георгий.
Приятно выдеть вас в своем блоге. Тестируемое приложение, это наша разработка на ZF, там довольно много SQL-запросов. APC включен. Сейчаскак раз её оптимизируем. Может быть посоветуете что-нибудь ещё?)
P.S. Вы будете в Киеве на ZFConf?
Советов по оптимизации sql? Да их сотни 🙂 Explain вам в зубы и Zend_Cache 🙂
Как оптимизировать ZF Саша рассказывал на майской Питерской конфе.
На ZFConf UA пока 50 на 50. Хотелось бы конечно.
Можно реквестировать тест этой тулзой http://habrahabr.ru/blogs/webdev/65128/?
Конечно, это одна из самых поопулярных тулз. Хотя мне больше нравится ab 🙂
К тестам надо прекладывать конфиги апач, енджинкса и пхп, т.к. Разные настройти могут сделать тест полностью непригодным
Согласен. Конфиг апача – по дефолту из пакета Ubuntu Server, конфиг nginx вот тут.