Monday, March 2, 2009

Httpd stress testbench in Erlang

just for training in Erlang programming, I've made some code for HTTP access test driver.

It reads existing access log of Apache(and its compatibles), and issues HTTP requests for designated target host.
It cannot,
  • issue POST, HEAD and other request than GET method
  • use cookies
  • wait for time intervals which are recorded in the log

To kick the test, you can follow process as below.


$ cd working_directory_which_has_logdir
$ erlc manager.erl
$ erlc logreader.erl
$ erlc client.erl
$
ls logdir
a.example.com
b.example.com
$ erl
-noshell -s manager start "logdir" 10000 20 3000 1 -s init stop

The last line is the command to initiate test.
erl is the name of Erlang interpretor.

-noshell option is to execute script in batch mode.

-s option (there are 2 blocks of them) designates each Erlang script.
first -s block means "manager:start("logdir", 10000, 20, 3000, 1)"
the first parameter specifies the place of logfiles.
second parameter 10000 specifies timeout in msec.
third parameter 20 specifies concurrency (how many clients issue request simultaneously).
4th parameter 3000 specifies interval in msec between each requests. This is required to save target host server to melt down :-P
5th parameter 1 is for KeepAlive flag.

and second -s block means "init:stop()" to exit batch Erlang operation.

I have confirmed that each client process can run simultaneously. Here is the sample result of tcpdump.

13:19:48.234946 IP 10.10.10.10.58500 > www.hoge.com.http: S 3505315617:3505315617(0) win 5840 <mss 1460,sackOK,timestamp 86795622 0,nop,wscale 3>
13:19:48.238005 IP 10.10.10.10.44873 > www.hoge.com.http: S 3499413688:3499413688(0) win 5840 <mss 1460,sackOK,timestamp 86795625 0,nop,wscale 3>
13:19:48.240203 IP 10.10.10.10.60753 > www.hoge.com.http: S 3510435421:3510435421(0) win 5840 <mss 1460,sackOK,timestamp 86795627 0,nop,wscale 3>
13:19:48.242465 IP 10.10.10.10.45900 > www.hoge.com.http: S 3500420864:3500420864(0) win 5840 <mss 1460,sackOK,timestamp 86795629 0,nop,wscale 3>
13:19:48.244827 IP 10.10.10.10.50124 > www.hoge.com.http: S 3495664924:3495664924(0) win 5840 <mss 1460,sackOK,timestamp 86795632 0,nop,wscale 3>
13:19:48.631375 IP www.hoge.com.http > 10.10.10.10.58500: S 320291303:320291303(0) ack 3505315618 win 64240 <mss 1460>
13:19:48.631504 IP 10.10.10.10.58500 > www.hoge.com.http: . ack 1 win 5840
13:19:48.675836 IP 10.10.10.10.58500 > www.hoge.com.http: P 1:108(107) ack 1 win 5840
13:19:48.769805 IP www.hoge.com.http > 10.10.10.10.58500: . ack 108 win 64240
13:19:48.769812 IP www.hoge.com.http > 10.10.10.10.44873: S 1269646951:1269646951(0) ack 3499413689 win 64240 <mss 1460>



You can access the code from http://github.com/kgbu/erlandom/tree/b661d83d128863667d0cf9fe86b2badb3416d4cd/httpstress

If you can read Japanese, my blog may help you.
http://d.hatena.ne.jp/kgbu/20080829/1219994676

No comments:

Post a Comment