Simulating High Traffic
If your problem has to do with your memory usage spiking at certain times of the day, it can be hard to figure out what’s happening since things are often running well when you’re able to check on them. When that’s the case, it’s important to be able to simulate the environment that’s causing the problem. A great tool for this is the httperf command. This is a tool for UNIX-like operating systems that allows you to measure web server performance. This is a fairly complex tool that can do a lot, but the most simple usage would be something like this:
httperf --hog --server=www.example.com --num-conns=1000 --rate=20 --timeout=5
That command will hit the supplied domain with 1000 connections at a rate of 20 connections per second. Connections that get no response within 5 seconds are dropped. The “–hog” parameter simply allows it to hog network ports on your system to allow for more outgoing connections. Depending on the amount of traffic you’re trying to simulate, you’ll need to adjust that.
So, to see what’s going on, you’ll likely want three terminal windows open. One will be SSH’d into your PS with top -c running sorted by memory (shift-m). Another will be SSH’d into your PS where you can repeatedly run free -m while httperf is running to monitor memory usage. And the third will be running httperf from your local machine (you do NOT want to run this from your PS itself).
This is great for profiling your sites and checking to see if caching is working. You can run this for each of your domains and see which ones affect your memory usage the most so you know where to focus your attention when working on optimizing things.
Another tool that can do something similar to this, but has fewer features is the Apache Benchmark tool. To use that you would use a command similar to this:
ab -n 1000 -c 20 http://www.example.com
That would attempt to create 1000 connections to http://www.example.com limiting itself to 20 concurrent connections. Between both tools you should be able to get a good idea of what’s going on with your sites under higher traffic.
You can find links to get more information on httperf and Apache Benchmark in the #External Links section below.