7.23.2006

test your rails app for slashdot/digg'ing

just put this in a script or something and you can see if your rails app chokes when you start getting alot of crazy traffic. Thanks to j'ey from #rubyonrails


require 'net/http'
page = "the_rails_page"
10000.times{
Thread.new{
Net::HTTP.start("localhost",3000){|h|h.get(page)}
}.join
}

3 comments:

Anonymous said...

woa, that's kinda heavy stuff.
In time I will try this for my site too.

Anonymous said...

But notice:
All you thousands of threads are not parallel.
You create a Thread and immediately join it.

Better is this:
require 'net/http'
t = Array.new
1000.times {
t << Thread.new {
Net::HTTP.start("your.server.tld",80) { |h|
h.get("/what/you/want")
}
}
}

t.each { |thread|
thread.join
}

Samuel "Artoo" Goodwin said...

heh, it's not a perfect test, mind you. And yes, rails does caching too. As far as testing depth goes, that's kinda specific to your app you're running and I don't really want to spend any kind of time abstracting it to work for any site.

The only real test of if you can handle a slashdot/digg'ing is to actually have it done to you... or hire a zombie-army of computers to try it for you.