Wednesday, November 13, 2013

Benchmark your HTTP server

Problem : Send 10,000 requests to a simple node.js server with variable number of concurrent requests.

1st test  - send 100 concurrent requests
2nd test -  send 500 concurrent requests

Following is my simple node.js server,
var http = require('http');

http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('Hello Blogger\n');
        }).listen(8000, '127.0.0.1');

console.log('Server running at http://127.0.0.1:8000/');
To overcome my initial problem I found this simple http benchmarking tool apache-bench aka ab. This comes packed with apache installation or you can simply install by giving sudo apt-get install apache2-utils on debian based distro.

Save above node server in ~/node_test/server/ directory as server.js.
cd to the server directory using terminal.
Before running the next step make sure you have node.js installed in your environment. If not use this git repo and the README to install node.js.

We bind our node based HTTP server to port 8000 because binding to ports lower than 1000, we need root access.

If you don't want to use node.js, you can use any HTTP server to try out apache-bench. I will move with my node server,

start node server using following command,
node server.js
You will see something similar,
udara@thinkPad:~/node_test/server$ node server.js
Server running at http://127.0.0.1:8000/
Lets run a simple test on our node server. Open another terminal and run,
ab -n 100 -c 50 http://127.0.0.1:8000/
-n Denotes number of requests to perform.
-c Denotes number of multiple requests to make(concurrency).
http://127.0.0.1:8000/ is my node server running in the same machine, on port 8000.

*Make sure you have the trailing / after port number.

This will run ab for 100 requests with 50 concurrent requests. If you have done everything right you will get something similar informative output,

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 127.0.0.1 (be patient).....done


Server Software:       
Server Hostname:        127.0.0.1
Server Port:            8000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      50
Time taken for tests:   0.022 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      11300 bytes
HTML transferred:       1200 bytes
Requests per second:    4624.06 [#/sec] (mean)
Time per request:       10.813 [ms] (mean)
Time per request:       0.216 [ms] (mean, across all concurrent requests)
Transfer rate:          510.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       1
Processing:     1    9   4.1      9      15
Waiting:        1    9   4.1      9      15
Total:          2    9   3.8     10      15

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     11
  75%     13
  80%     14
  90%     15
  95%     15
  98%     15
  99%     15
 100%     15 (longest request)

Now we can run all different combinations of actual benchmarking tests against our own node server.
ab -n 10000 -c 100 http://127.0.0.1:8000/
ab -n 10000 -c 500 http://127.0.0.1:8000/ 
You can use apache-bench to benchmark any HTTP server as I have mentioned earlier, this is pretty helpful tool to benchmark, compare your HTTP server environments.

run  man ab  to find out other options available in Apache HTTP server benchmarking tool ab.

Happy benchmarking !!!

No comments:

Post a Comment