Introducing Trample: A Better Load Simulator
Most load sim tools make requests to a static list of urls. They spawn n threads and make requests to the urls on the list in succession, in each thread. Unfortunately, though, if your applicaition makes use of any kind of caching (including your database's internal caching facilities), this kind of load simulation is unrealistic.
The data required to serve a single set of urls is likely to fit nicely in the database server's cache (even on a small server). So, having a single user hammer a finite set of pages will make your application look much faster than it really is.
Unless your load patterns really look that way, you're testing for a scenario that you'll never see.
Introducing Trample
Trample is a more flexible load simulator. Instead of a static list of urls, trample's configuration language is ruby. Using ruby's blocks (lambda functions), it's possible to randomize the requests that get made in each thread, as well as the user that logs in.
Let's look at an example config:
Trample.configure do concurrency 20 iterations 10 login do post "http://mysite.com/login" do {:username => User.random.username, :password => "swordfish"} end end get "http://mysite.com/posts/:id" do {:id => Post.random.id} end post "http://mysite.com/posts/:id/comments" do {:id => Post.random.id, :author => "James Golick", :body => "lorem ipsum"} end end
This config will cause trample to spawn 20 threads. In each thread:
- Trample will begin by sending a POST request to http://mysite.com/login with the result of the block as its POST body.
- Then, trample will GET http://mysite.com/posts/(some interpolated value here, based on the result of the block).
- Then, trample will POST http://mysite.com/posts/(interpolated value here)/comments with a POST body that includes the remainder of the parameters returned from the block
- Repeat steps 2-3 nine (iterations - 1) more times.
It's possible to create fairly realistic load simulations with a configuration like this. Each thread will start by logging in as a different user. And, the threads will each visit different URLs. The ratio of cache hits to misses should be far closer to what they look like under real load.
Running Trample
To run trample:
$ trample start /path/to/your/trample/config.rb
I've tested trample on ruby 1.8.x, ruby 1.9, and JRuby. JRuby has the advantage of native threading, but the drawback of JVM warmup times. So, theoretically, JRuby should be the best platform for running long tramples. Ruby 1.9 should be fastest for shorter tramples. I could be wrong, though. YMMV.
Get It!
Get trample as a gem:
$ sudo gem install giraffesoft-trample
Or get the source from github.