Table of Contents
I tried stress test with Apache Bench for Web API server.
Environment
The environment of the client machine I used for the test this time.
- OS: Ubuntu 16.04
Apache Bench
Apache Bench is the tool which makes stress test easy. It has not many functions for stress test, but it is easy to use.
What we can do
- POST / GET Request
What we cannot do
- DELETE Request
- Change parameter for each request
- Use scenario
Install Apache Bench
Install it with the following command.
1 |
sudo apt-get install apache2-utils |
Test POST request
POST リクエスト でテストをする今回のテストでは次のようにしました。
1 |
ab -n 1000 -c 100 -p ./sample.json -T "application/json; charset=utf-8" "http://host.com/api_endpoint" |
To send JSON data, create sample.json
and write JSON.
To execute test, write the command as ab [options] [http[s]://]hostname[:port]/path
.
Option
ab -h
shows help. Here I introduce help descriptions of options I used this time.
- -n
- The number of requests.
- -c
- The number of requests to be sent at once.
- -p
- The file including sending data in POST request. When we use PUT request, add
-u
option. - -T
- Content Type
Output
The following aoutput appears. The number of requests in one second is also shown.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
This is ApacheBench, Version 2.3 <$Revision: 1706008 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking host.com (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.8.1 Server Hostname: host.com Server Port: 80 Document Path: /api_endpoint Document Length: 4367 bytes Concurrency Level: 100 Time taken for tests: 7.748 seconds Complete requests: 1000 Failed requests: 187 (Connect: 0, Receive: 0, Length: 187, Exceptions: 0) Total transferred: 3904665 bytes Total body sent: 260000 HTML transferred: 3556542 bytes Requests per second: 129.06 [#/sec] (mean) Time per request: 774.814 [ms] (mean) Time per request: 7.748 [ms] (mean, across all concurrent requests) Transfer rate: 492.14 [Kbytes/sec] received 32.77 kb/s sent 524.91 kb/s total Connection Times (ms) min mean[+/-sd] median max Connect: 6 21 11.0 19 50 Processing: 88 704 736.2 391 3355 Waiting: 87 699 735.5 385 3336 Total: 96 725 734.6 416 3378 Percentage of the requests served within a certain time (ms) 50% 416 66% 567 75% 677 80% 846 90% 2033 95% 2440 98% 3080 99% 3236 100% 3378 (longest request) |