Hi Folks - A week or two ago, I pinged this list for recommendations on
a load testing gem. Unfortunately, didn't see much response from that
that pointed me in the right direction. So I've set about to write my
own, using threads, and can't find proper resources to help me
understand what's going on w/ said threads.
Here's the two key methods I'm using and figure are the source of my
troubles. First question is whether there's any glaring errors here
that I'm missing:
class ThreadedLoadTester
def initialize(users, apis, session=nil)
@threads = []
@count = users
@session = session
1.upto @count.to_i do
@threads << Thread.new do
Thread.current[:hi5] = Hi5fbapi.new 'redacted params'
Thread.current["api_calls"] = []
apis.each do |api|
#get_call returns a proc object w/ a snippet of test code
Thread.current["api_calls"] << get_call(api)
end
Thread.stop
end
end
end
def run_threads()
@threads.each do |thr|
thr[:api_calls].each do |api|
p api.call thr[:hi5], @session
end
end
@threads.each {|t| t.wakeup.join}
return nil
end
Basically, I spin up a bunch of threads when I initialize the object,
populate an array in each thread w/ a series of proc objects, and then
put them to sleep. Then, when I run_threads(), the idea is to iterate
over each thread, iterate over the thread's array of procs, and call
each one. Oh, and this object is consumed by a sinatra-based web app.
This works sometimes. And sometimes it segfaults in a nasty way. I'm
having a hard time finding the technical details of how threading in
Ruby, particularly 1.9.2-p0, works. Any pointers?
Thanks,
Alex