May 3, 2011

Simple web server load testing

I recently ran into ab, which is an Apache HTTP server benchmarking tool. The following is an invocation where I'm running a load test on a local tomcat instance which is using 1000 requests with 10 concurrent threads.

mike@shiner $ ab -n 1000 -c 10 http://localhost:8080/test-ui/
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 localhost (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:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8080

Document Path:          /test-ui/
Document Length:        7891 bytes

Concurrency Level:      10
Time taken for tests:   13.262 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      8054000 bytes
HTML transferred:       7891000 bytes
Requests per second:    75.40 [#/sec] (mean)
Time per request:       132.624 [ms] (mean)
Time per request:       13.262 [ms] (mean, across all concurrent requests)
Transfer rate:          593.05 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0      12
Processing:     5  132 349.6     28    3087
Waiting:        5  130 349.4     26    3087
Total:          5  132 349.7     28    3087

Percentage of the requests served within a certain time (ms)
  50%     28
  66%     84
  75%    145
  80%    168
  90%    264
  95%    376
  98%   1450
  99%   2412
 100%   3087 (longest request)

The tool has a lot of really great features and I'll try to exemplify some of them here. The following shows how you can change the User-Agent to a variant of Internet Explorer (thanks goes to www.useragentstring.com for the value). I've also set the verbosity level to 4 so I can verify the 'User-Agent' value is set as intended. I've excluded the output for brevity.

mike@shiner $ ab  -v 4 -H "User-Agent: Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"   http://localhost:8080/test-ui/

Next is an example where I set the value of a cookie. I run into situations where I need to evaluate code for cell testing. It happens to be that our cell testing code is dependent on cookie values.

mike@shiner $ ab -n 1000 -c 10 -C "cellNum=10"  http://localhost:8080/test-ui/

The following is an example of setting the -G flag, which will output a file named 'perf.out' which can be used with GnuPlot. The file doesn't have to be used with just GnuPlot. It can also be used with IDL, Mathematica, Igor, and Excel.

mike@shiner $ ab -n 1000 -c 10 -G perf.out http://localhost:8080/test-ui/

April 30, 2011

Finding the memory usage of a process

I recently needed to figure out how to determine the memory usage of a process so I could log it over time. I used the following command to accomplish this.

mike@shiner $ ps -p 7557 -o pid,vsz,rss
  PID      VSZ    RSS
 7557  1983664 298536

You'll need to replace '7557' with the process id you're investigating. The meaning of 'VSZ' and 'RSS' is copy and pasted here from the man page:

     rss        resident set size
     vsz        virtual size in Kbytes (alias vsize)

'RSS' represents the amount of memory resident in RAM. The rest of the memory is held in swap space or the filesystem. 'VSZ' is the amount of virtual memory allocated to the process.

April 26, 2011

Moving multiple files

I recently learned that you can move multiple files in one invocation of mv. As long as the last argument is a directory, then all the previous files/directories will be moved into it.

mike@shiner $ mv one.txt two.txt three.txt foobar

If the last argument isn't a directory, then you'll see an error.

mike@shiner $ mv one.txt two.txt three.txt 
mv: target `three.txt' is not a directory