Når vi skal teste ydelse på webservere og webapplikationer er værktøjet “ab” bedre kendte om Apache Benchmark uundværligt, der findes mange forskellige og jeg vil ikke gennemgå dem i dybden her, jeg vil bare “lægge værktøjet” i dine hænder og vise dig basal brug af det … så går jeg ud fra at dig og “man” selv finder ud af resten 😉
Alternativt laver jeg nok en follow-up på et tidspunkt hvor jeg bruger det til en eller anden konkret opgave.
Til testformål opretter jeg 2 filer på specialhosting.dk, først slow.php:
<?
sleep(1);
?>
og fast.php:
<?
// Do nothing
?>
Altså et script der laver ingenting og et andet der lavet ingenting i 1 sekund. Så lad os få installeret httperf og ab på vores testmaskine:
root@lab1:~# apt-get install httperf apache2-utils
Vi starter med at køre ab mod begge scripts, først fast.php:
root@lab1:~# ab http://www.specialhosting.dk/fast.php
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/
Benchmarking www.specialhosting.dk (be patient).....done
Server Software: Apache/2.2.16
Server Hostname: www.specialhosting.dk
Server Port: 80
Document Path: /fast.php
Document Length: 0 bytes
Concurrency Level: 1
Time taken for tests: 0.023 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Total transferred: 210 bytes
HTML transferred: 0 bytes
Requests per second: 43.88 [#/sec] (mean)
Time per request: 22.792 [ms] (mean)
Time per request: 22.792 [ms] (mean, across all concurrent requests)
Transfer rate: 9.00 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 21 21 0.0 21 21
Processing: 2 2 0.0 2 2
Waiting: 2 2 0.0 2 2
Total: 23 23 0.0 23 23
og så slow.php:
root@lab2:~# ab http://www.specialhosting.dk/slow.php
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/
Benchmarking www.specialhosting.dk (be patient).....done
Server Software: Apache/2.2.16
Server Hostname: www.specialhosting.dk
Server Port: 80
Document Path: /slow.php
Document Length: 0 bytes
Concurrency Level: 1
Time taken for tests: 1.002 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Total transferred: 210 bytes
HTML transferred: 0 bytes
Requests per second: 1.00 [#/sec] (mean)
Time per request: 1001.661 [ms] (mean)
Time per request: 1001.661 [ms] (mean, across all concurrent requests)
Transfer rate: 0.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1001 1001 0.0 1001 1001
Waiting: 1001 1001 0.0 1001 1001
Total: 1002 1002 0.0 1002 1002
You see? En masse dejlige tal man kan bruge til at lave sammenligninger med, husk og spørg din server-administrator om lov før du kører Benchmark mod dit webhotel 🙂