Статьи

Тестирование производительности Apache

Я начал работать с ab — включен с Apache, а не новый инструмент. ab позволяет проводить тестирование производительности веб-страниц, сайтов и даже динамических скриптов в зависимости от пользовательской нагрузки.

AB позволяет создавать один или несколько запросов в секунду и предоставляет хороший отчет о результатах.

Некоторые из ключевых опций, которые можно просмотреть, запустив ‘man ab’ в любой установке Linux или OS X с установленным Apache.

Параметры:

-k: Включает HTTP KeepAlive, так что несколько запросов выполняются в течение одного сеанса.

-n: количество запросов на выполнение, как в 150. Они будут выдаваться один за другим, пока не будут выполнены.

-t: выдает ограничение по времени, в течение которого могут выполняться запросы.

-c: допускает несколько запросов одновременно, а не по одному. Это может быть полезно для проверки производительности скрипта.

-Имя пользователя и пароль, разделенные двоеточием: это используется для отправки аутентификации, если требуется вход в систему на тестируемом сайте.

Есть несколько других вариантов, включая работу через прокси-серверы, добавление заголовков и файлов cookie.

Результаты выводятся в командную строку (пример ниже из установки OS X localhost Apache):

This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 1456 bytes Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)

This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 1456 bytes Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)

This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 1456 bytes Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)

This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 1456 bytes Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)

This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 1456 bytes Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)

This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80 Document Path: / Document Length: 1456 bytes Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441 Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)

Вы также можете вывести результаты в файл CSV, используя опцию «-e filename». ‘-w’ выводит результаты в таблицу HTML. Существует возможность использовать ab изнутри PHP, чтобы генерировать нагрузочные тесты из веб-браузера и возвращать результаты, хотя я еще не пытался это сделать. Прежде всего, я запускал ab на серверах разработки до перехода к производству, а затем снова запускал его в производственной среде до выпуска.