Wednesday, February 11, 2009

To run a cookie based web session in httperf...

I was trying to mimic how a user interacts with a web application using httperf tool. I installed httperf in my linux machine using source code from here:
http://www.hpl.hp.com/research/linux/httperf/download.php
(The originators of this tool are D. Mosberger and T. Jin from hp few years back)

Httperf is a command line tool. You have to type httperf followed by the options.
Httperf has an option called --wsesslog to simulate session.
#httperf --server localhost --port 80 --wsesslog 1,1,sessionfile --print-reply > outfile

Now the web server sends the pages requested by URLs in the session file. When you use --print-reply option the the HTML header and body of each resulting page is written to outfile. Otherwise only the performance information of the web server and the network will appear as the output of the command.


A user is represented by the sequence of URLs separated by think time which is called as session. Each URL in the session can be appended with POST data.
The format of the sessionfile is something like this:
/simple/login.php method=POST contents="username=user&password=pass"

Most imprtantly, if you are to have URLs with POST data you must state the Content-Type header. I set content type to 'Content-Type: application/x-www-form-urlencoded\n' and it worked for me.

Httperf currently allow an option called --add-header but that header holds equally for all the URLs in the session file. But for my task I needed diferent headers for different URLs in my session file. Fortunately I found a patch for getting this done:
http://www.overset.com/2008/03/27/load-test-ajax-applications-with-httperf/

After applying the patch I could use an additional attribute for the URLs in my sessionfile as follows:
/simple/login.php method=POST headers='Content-Type: application/x-www-form-urlencoded\n' contents="username=user&password=pass"

Now its time to play with Cookies in httperf.... (think)
Of course by simply typing --session-cookie option with httperf command worked with a simple php site with just one cookie. But for me its to work with two cookies sent by server in two parts of the same header.

Will get back to this once I get some good news! :)

1 comment:

sulo said...

Hey I gave up Cookie based login. But fortunately my web applications supported cookieless login. So I managed to run a session. Hurrah!!