apacheApache Benchmark Tool merupakan salah satu pilihan program yang berfungsi untuk melakukan uji coba kehandalan suatu layanan web dalam menerima request dari http client. Penggunaan serta penerapannya juga bisa dilakukan sebelum atau setelah proses optimalisasi suatu sistem ataupun suatu halaman web, baik perubahan php handler, serta kondisi lain sebagainya di sisi server yang telah diterapkan guna mengetahui kehandalan atas perubahan yang telah diterapkan di sisi server tersebut.

Hasil dari uji atau benchmark tersebut dapat dijadikan pertimbangkan lebih lanjut apakah suatu web service sudah cukup optimal dan stabil atas standar target yang ditetapkan dalam melakukan pemrosesan dan memberikan respon dari request yang diterima? ataukah perlu dilakukan upgrade untuk peningkatan kualitas layanan lebih lanjut? baik dengan optimasi atau tweak kembali di sisi halaman web, script, konfigurasi layanan web, hardware upgrade atau bahkan peningkatan infrastruktur pendukung lainnnya jika sekiranya memang diperukan.

Installasi HTTPD Tool

Proses instalasi dapat menggunakan apt-get apabila menggunakan Sistem Operasi GNU/Linux Debian/Ubuntu sebagai berikut.

chroot@id:~$ sudo apt-get update -y
chroot@id:~$ sudo apt-get install -y apache2-utils

Apabila menggunakan Sistem Operasi GNU/Linux RHEL/CentOS, pertama pastikan terlebih dahulu bahwa nilai dari service httpd* tidak berada dalam kondisi exclude melalui file konfigurasi /etc/yum.conf tersebut agar dapat melakukan installasi paket httpd-tools.

[root@centos ~]# vim /etc/yum.conf
[main]
exclude=bind-chroot courier* dovecot* httpd* exim* filesystem kernel kernel-xen kernel-smp kernel-pae kernel-PAE kernel-SMP kernel-hugemem kernel-debug* kmod-* mod_s
sl* mydns* mysql* nsd* php* proftpd* pure-ftpd* spamassassin* squirrelmail*
tolerant=1
errorlevel=1
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=https://bugs.centos.org/set_project.php?project_id=19&ref=https://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

Hapus nilai httpd* dari variabel exclude pada baris kedua dari atas, save kemudian install menggunakan perintah yum. Setelah paket httpd-tools terinstall maka bisa disesuaikan kembali nilai dalam variabelnya tersebut.

[root@centos ~]# yum -y install httpd-tools

Apache Benchmarking

Apache benchmark bekerja dengan menjalankan suatu script yang disebut dengan ab. Detail informasi petunjuk penggunaan dapat merujuk tautan Apache Benchmark disini atau dapat langsung merujuk manual penggunaan perintah tersebut sebagai berikut.

Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests     Number of requests to perform
-c concurrency  Number of multiple requests to make
-t timelimit    Seconds to max. wait for responses
-b windowsize   Size of TCP send/receive buffer, in bytes
-p postfile     File containing data to POST. Remember also to set -T
-u putfile      File containing data to PUT. Remember also to set -T
-T content-type Content-type header for POSTing, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity    How much troubleshooting info to print
-w              Print out results in HTML tables
-i              Use HEAD instead of GET
-x attributes   String to insert as table attributes
-y attributes   String to insert as tr attributes
-z attributes   String to insert as td or th attributes
-C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
-H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute    Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute    Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port   Proxyserver and port number to use
-V              Print version number and exit
-k              Use HTTP KeepAlive feature
-d              Do not show percentiles served table.
-S              Do not show confidence estimators and warnings.
-g filename     Output collected data to gnuplot format file.
-e filename     Output CSV file with percentages served
-r              Don't exit on socket receive errors.
-h              Display usage information (this message)
-Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

Dokumentasi artikel ini akan melakukan proses pengujian atau benchmarking layanan web dengan menggunakan opsi -n untuk uji 10000 total paket request dengan opsi -c untuk concurrent connections sebesar 100. Dengan kata lain, 100 paket pertama akan dikirimkan (request) dalam waktu yang bersamaan, setelahnya kemudian 100 paket request berikutnya atau yang kedua menyusul, dan seterusnya sampai mencapai 10000 paket request terkirim terhadap URL tujuan. Dari total keseluruhan paket yang terkirim tersebut akan tercatat hasilnya berupa nilai statistik connection time. Pastikan dalam penulisan URL tujuan diakhiri dengan karakter slash (/).

root@centos [~]# ab -c 100 -n 10000 https://www.chrootid.com/

Hasilnya adalah sebagai berikut.

This is ApacheBench, Version 2.3 <$Revision: 655654

gt;
Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://www.zeustech.net/
Licensed to The Apache Software Foundation, https://www.apache.org/

Benchmarking www.chrootid.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests

Server Software: Apache
Server Hostname: www.chrootid.com
Server Port: 80

Document Path: /
Document Length: 111 bytes

Concurrency Level: 100
Time taken for tests: 48.599 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3160000 bytes
HTML transferred: 1110000 bytes
Requests per second: 205.77 [#/sec] (mean)
Time per request: 485.988 [ms] (mean)
Time per request: 4.860 [ms] (mean, across all concurrent requests)
Transfer rate: 63.50 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 222 224 1.3 223 255
Processing: 223 256 179.6 223 2219
Waiting: 222 256 179.6 223 2219
Total: 445 479 179.6 446 2445

Percentage of the requests served within a certain time (ms)
50% 446
66% 449
75% 449
80% 449
90% 450
95% 472
98% 1118
99% 1567
100% 2445 (longest request)

Pertimbangan lanjut dari hasil benchmark tersebut bisa berdasarkan nilai statistik connection times, baik dari sisi request per second maupun time per request mengingat tentu semakin tinggi traffic concurrent request maka dapat berbanding lurus dengan semakin tingginya nilai statistik connection time baik dari sisi konektifitas maupun pemrosesan oleh web server. Jika hasilnya dirasa sudah tidak begitu responsif, tidak optimal, hang bahkan down, maka sudah dapat dipertimbangkan tweak atau optimalisasi lebih lanjut di sisi web script, web  server atau bahkan upgrade di sisi hardware jika sekiranya diperlukan.

Hasil dari apache benchmark tentu bersifat relatif sesuai dengan kondisi dari resource server mulai dari cpuload atau ram usage, bandiwidth, throughput atau active traffic, kondisi konfigurasi web server serta kondisi aplikasi suatu web di dalam web server terkait.