RSS

how to test file uploading with apache benchmark

25 May

Useful link for explanation of metrics http://ngenuity.ngmoco.com/2012/01/testing-with-apache-bench.html

There is an extension for multiple urls: http://code.google.com/p/apachebench-for-multi-url/

Supported blog for some examples and experience of how to use AB:

There really are some difficult for how to compose the data which is sent via apache benchmark. A sample below is from an experienced guy

-- Post data included in file post_data
your_name=fredrik&fruit=ApricotFromAB

-- man ab to see options
ab -n 20 -c 5 -p post_data -v 4 -T 'application/x-www-form-urlencoded' http://hroch486.icpf.cas.cz/cgi-bin/echo.pl

The below content is from the 3rd link

All the content below is copied from this link. This is because sometimes I cannot access this link. It is only for recording somethings.

Multipart posting with Apache Benchmark

Last week I wanted to load test an upload functionality created for one of the projects. The testing team was busy with other stuff so I decided to do it on my own. Being a hardcore programmer and someone who has never used any of the regular testing tools (read M$ Window$ based tools) I had the only option of using Apache Benchmark on my Ubuntu 10.10

Since I had already used ab (the Apache Benchmark command name), I was pretty confident that within few minutes I will be done. But multipart form posting wasn’t as straightforward as I had thought. My initial assumption was to provide a file path to -p option of ab and it would handle the stuff required for multipart posting. Unfortunately that wasn’t the case. I realized that I had to provide a file name but it should contain the complete information about the data to be posted. In other words, I had to manage the boundary required for multipart posting.

After some research and this small but important tip, I managed to prepare the POST data in the required format along with the correct Content-type required by Apache Benchmark. The final command looked like

1.ab -n 10 -c 2 -C PHPSESSID=rk53j7gsrmaiuc3gvo86ipltr1 -p /var/www/post_data.txt -T "multipart/form-data; boundary=1234567890"http://my-domain.com/upload.php

Following is the breakdown of options provided to the command –

I provided the cookie information (option -C ) along with the command since my upload script checks for authentication.
-p allows me to provide a file name which contains the complete information about the data to be POSTed along with multipart boundaries.
-T is for Content-type header. This is where I also tell ab about the boundary in my POST data along with the standard multipart/form-data content type.
And then finally the URL of where all the data has to be posted.

The contents of the post_data.txt file are

01.--1234567890
02.Content-Disposition: form-data; name="ID"
03.
04.3
05.--1234567890
06.Content-Disposition: form-data; name="videofile"; filename="ab1_pod.avi"
07.Content-Type: video/x-msvideo
08.
09.[base64 encoded file content here]
10.--1234567890--

Remember that the format of the file should be exactly the same (your boundary label can be different than mine though). Even if you miss a single new line or add an extra new line somewhere then you won’t get the expected results.

Finally to base64 encode the file to be posted, you can simply use PHP code as follows and paste the content in the above placeholder.

1.echobase64_encode(file_get_contents('/home/aditya/Videos/my_video.avi'));

That’s it. Happy testing.
As always, comments and suggestions are most welcome.

Reference

https://snipt.net/fredrikbach/command-to-run-performance-test-post-with-apachebench/

 
Leave a comment

Posted by on May 25, 2012 in Cloud Computing

 

Leave a comment