Sabtu, 27 Desember 2014

Benchmark Response Time antara NGINX HHVM vs NGINX PHP5-FPM vs APACHE

1. Overview

Performance serta scalability adalah dua hal yang penting yang harus selalu diperhatikan dalam pemilihan technology stack pada sebuah aplikasi web, salah satu aspek yang penting adalah pemilihan web server. Web server yang tepat dari segi performance dan scalability akan membuat sebuah situs web tetap mampu online dan beroprasi secara normal walaupun pengakses web meningkat.

Di dalam artikel ini saya akan menuangkan hasil percobaan benchmark antara tiga web server, nginx dengan hhvm, nginx dengan php5-fpm, dan apache. Benchmark tersebut saya lakukan untuk mengetahui response time dari ke tiga web server tersebut ketika mengakses sebuah halaman situs web.

Halaman situs web yang digunakan ketika benchmark adalah sebuah halaman dari situs web yang dikembangkan dengan cakephp framework dan dideploy di lingkungan localhost.

2. Proses benchmark

Benchmark dilakukan dengan menggunakan ApacheBench dan gnuplot untuk menampilkan hasil benchmark dalam bentuk grafik. Masing-masing web server telah dicoba untuk diakses dengan jumlah request yang sama sebanyak 1000 dengan jumlah concurrency 100. Output dari ketiga percobaan disimpan di tiga file yang selanjutnya ditampilkan dalam sebuah grafik dengan bantuan gnuplot.

Setelah situs web dideploy dan diberi virtualhost task.local yang sama untuk masing-masing jenis web server, maka selajutnya dilakukan benchmark dengan mengeksekusi command berikut ini pada console

ab -c100 -n1000 -g nginx_with_hhvm.txt  http://task.local/

- ab adalah command line yang dieksekusi
- -c adalah jumlah concurrency level yang dipakai
- -n adalah jumlah request
- -g adalah nama file untuk output
- bagian terakhir adalah url dari halaman web yang akan di test

Command tersebut dieksekusi sebanyak tiga kali, untuk web server nginx dengan hhvm, nginx dengan php5-fpm dan untuk apache.

3. Hasil

Berikut ini adalah output console untuk ketiga percobaan eksekusi apachebench yang telah dilakukan

Berikut ini adalah hasil eksekusi command apachebench di atas untuk web server nginx dengan hhvm:
herdiansc@herdiansc:~/Documents/Resources/benchmarks$ ab -c100 -n1000 -g nginx_with_hhvm.txt  http://task.local/
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 task.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/1.1.19
Server Hostname:        task.local
Server Port:            80

Document Path:          /
Document Length:        10544 bytes

Concurrency Level:      100
Time taken for tests:   3.909 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      10730000 bytes
HTML transferred:       10544000 bytes
Requests per second:    255.82 [#/sec] (mean)
Time per request:       390.900 [ms] (mean)
Time per request:       3.909 [ms] (mean, across all concurrent requests)
Transfer rate:          2680.62 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       3
Processing:    20  339  61.0    337     676
Waiting:       20  339  61.0    337     675
Total:         23  339  60.8    337     676

Percentage of the requests served within a certain time (ms)
  50%    337
  66%    370
  75%    384
  80%    389
  90%    403
  95%    420
  98%    457
  99%    483
 100%    676 (longest request)
herdiansc@herdiansc:~/Documents/Resources/benchmarks$ 


Berikut adalah hasil untuk web server nginx dengan php5-fpm:
herdiansc@herdiansc:~/Documents/Resources/benchmarks$ ab -c100 -n1000 -g nginx_with_php5_fpm.txt  http://task.local/
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 task.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/1.1.19
Server Hostname:        task.local
Server Port:            80

Document Path:          /
Document Length:        10544 bytes

Concurrency Level:      100
Time taken for tests:   15.992 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      10742000 bytes
HTML transferred:       10544000 bytes
Requests per second:    62.53 [#/sec] (mean)
Time per request:       1599.220 [ms] (mean)
Time per request:       15.992 [ms] (mean, across all concurrent requests)
Transfer rate:          655.96 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.7      0       3
Processing:    63 1525 274.4   1589    1808
Waiting:       56 1507 271.6   1571    1799
Total:         66 1526 273.8   1589    1808

Percentage of the requests served within a certain time (ms)
  50%   1589
  66%   1613
  75%   1629
  80%   1639
  90%   1670
  95%   1700
  98%   1737
  99%   1762
 100%   1808 (longest request)
herdiansc@herdiansc:~/Documents/Resources/benchmarks$ 

Dan yang terakhir berikut adalah hasil untuk web server apache:
herdiansc@herdiansc:~/Documents/Resources/benchmarks$ ab -c100 -n1000 -g apache.txt  http://task.local/
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 task.local (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.22
Server Hostname:        task.local
Server Port:            80

Document Path:          /
Document Length:        10544 bytes

Concurrency Level:      100
Time taken for tests:   58.540 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      10756000 bytes
HTML transferred:       10544000 bytes
Requests per second:    17.08 [#/sec] (mean)
Time per request:       5853.979 [ms] (mean)
Time per request:       58.540 [ms] (mean, across all concurrent requests)
Transfer rate:          179.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.4      0       5
Processing:  5036 5654 1748.2   5070   12988
Waiting:       32  637 1734.5     58    7952
Total:       5037 5654 1749.4   5070   12992

Percentage of the requests served within a certain time (ms)
  50%   5070
  66%   5100
  75%   5144
  80%   5191
  90%   6970
  95%  10487
  98%  11841
  99%  12760
 100%  12992 (longest request)
herdiansc@herdiansc:~/Documents/Resources/benchmarks$

Beberapa yang menarik pada hasil benchmark di atas adalah pada bagian time taken for tests, requests per second, dan time per request. Supaya lebih memperjelas perbedaannya berikut adalah hasil untuk ketiga hal tersebut:

Table benchmark

Pada gambar di atas nginx dengan hhvm dibelakangnya mendominasi baik dari segi kecepatan response ataupun banyaknya request yang bisa ditangani. Sedangkan sebaliknya dari nginx dengan hhvm, apache adalah yang paling lambat dari segi kecepatan response, paling sedikit dari segi jumlah request yang bisa ditangani per satuan waktu.

4. Grafik

Berikut adalah grafik yang menunjukkan bagaimana pergerakkan kurva response time seiring meningkatnya jumlah request untuk masing-masing web server.

Grafik Benchmark


Pada grafik tersebut, pergerakan kurva untuk web server nginx dengan hhvm cenderung stabil berada pada response time yang cepat yakni jauh di bawah 2 detik, sedangkan untuk apache hampir stabil diangka waktu yang lebih lama yakni 4 detik, bahkan meningkat jauh pada jumlah request di atas 900.

Selain itu yang cukup menarik adalah kurva yang ditunjukkan oleh hasil percobaan web server nginx dengan php5-fpm, response time nya cukup cepat yakni stabil diangka mendekati 2 detik, hal tersebut cukup baik dibandingkan dengan apache, walaupun masih kalah dibandingkan dengan nginx dengan hhvm.

5. Kesimpulan

Dari segi response time ataupun waktu response untuk ketiga web server tersebut, nginx yang "ditenagai" oleh hhvm di belakangnya jauh lebih cepat dibandingkan dengan nginx dengan php5-fpm dan apache. Sedangkan nginx dengan php5-fpm masih lebih cepat dibandingkan apache. Dan yang paling lambat adalah apache dibandingkan kedua web server tersebut.

Tidak ada komentar:

Posting Komentar