Home | Back


การวัด Benchmark ของ Web Application ด้วย Apache Utilily

Tuesday, 12 March 2013



ในการพัฒนาระบบสารสนเทศนั้น การเลือกเทคโนโลยีมาใช้พัฒนานั้นเป็นสิ่งสำคัญ บางครั้งเราอยากจะรู้เทคโนโลยีที่เรานำมาใช้ทำ Web Application มีความสามารถในการตอบสนองการทำงานได้ดีหรือน้อยกว่ากัน อย่างเช่น งานแบบเดียวกัน ถ้าใช้ php+apache2 แล้วจะสามารถรองรับได้กี่ request per second แต่ถ้าใช้ Bottle+Gevent จะสามารถรองรับ Request per second ได้ดีกว่าแค่ไหนนั้น เราสามารถทำการทดสอบได้ด้วยโปรแกรมชุดเอนกประสงค์ Apache Utility ได้ครับ โดยทำการทดลองใน Ubuntu ดังนี้ครับ

1. ติดตั้ง apache2-utils

เริ่มต้นก็ต้องทำการติดตั้ง Package ที่ชื่อ apache2-utils ก่อนดังนี้ครับ

$ sudo aptitude install apache2-utils

2. การทดสอบเวบไซต์ด้วยคำสั่ง ab

หลังจากติดตั้ง apache2-utils แล้ว เราสามารถทำ Benchmarking ตัว Web Application ได้ด้วยคำสั่ง ab ดังตัวอย่างต่อไปนี้ครับ

$ ab -n 1000 -c 20 http://edoc2.rmutsv.ac.th/
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 edoc2.rmutsv.ac.th (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:        
Server Hostname:        edoc2.rmutsv.ac.th
Server Port:            80

Document Path:          /
Document Length:        3734 bytes

Concurrency Level:      20
Time taken for tests:   6.857 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      3871000 bytes
HTML transferred:       3734000 bytes
Requests per second:    145.84 [#/sec] (mean)
Time per request:       137.137 [ms] (mean)
Time per request:       6.857 [ms] (mean, across all concurrent requests)
Transfer rate:          551.31 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        3   61 108.6     38    1071
Processing:    14   74  81.2     46    1027
Waiting:       12   67  61.4     43     554
Total:         22  135 129.8     99    1158

Percentage of the requests served within a certain time (ms)
  50%     99
  66%    154
  75%    168
  80%    173
  90%    191
  95%    205
  98%    572
  99%   1058
 100%   1158 (longest request)

จากตัวอย่างจะใช้คำสั่ง ab -n 1000 -c 20 http://edoc2.rmutsv.ac.th/ โดย -n 1000 หมายถึงให้สร้าง request 1000 ครั้ง โดย -c 20 จะเป็นการกำหนด concurrency เท่ากับ 20 หรือหมายถึงให้สร้าง request แบบพร้อม ๆ กันในครั้งเดียวที่ละ 20 request นั่นเอง จากนั้นก็ตามด้วย เวบที่เราจะทำการทดสอบ โปรแกรมก็จะรายงานผลเป็นค่าต่าง ๆ ให้เราได้ทราบเพื่อนำไปเปรียบเทียบกับตัวอื่น ๆ ได้ครับ ปล. อย่าเอาไปใช้ยิงเวบใครเข้าละครับ มันผิดกฏหมายและผิดจรรยาบรรณนักคอมพิวเตอร์ ให้ใช้เพื่อทดสอบเวบของตัวเองเท่านั้นนะครับ ขอให้สนุกกับการพัฒนาระบบครับ :)



Home | Back