Fine-tuned scheduling: backgroundrb?


I’d like to make a few requests per second to another method using,
for example, backgroundrb (any other suggestions are welcome as

I have considered using jRuby to enhance the use of threads and I’m
quite sure that’s the way to go. So what I’d like Rails to do is,
based on a value in a database, calculate the number of requests it
has to make in a certain timeframe. For example, when it has to make
300 requests in 60 seconds, I’d like Rails to execute the method in a
new thread every 200 milliseconds. It can be off by a bit, but I want
to make sure it has 25 requests done by 5 seconds and 150 by 30.
That’s important. It can’t be finished by 50 seconds and it can’t be
resting for a whole second, for example.

The only solutions I’ve found so far are basically making Rails
execute the method and then sleep for a given time, but that doesn’t
feel right. I’m not even sure whether that accepts a time in

I hope you can help. Thanks.

I got a little bit further. I could make Rails sleep for just a few
milliseconds between executing the threads of course. It’s not pretty
though. If anyone knows of a better way, please tell me!

Will the following give me any problems? I can imagine ActiveRecord
could clot up when some of the threads write at the same time, or
won’t I have to worry about that?

Worker FooBar
def scheduler(queries_per_minute, collection)
sleeptime = 60 / queries_per_minute
collection.each do |item| do
sleep sleeptime

def executor
#execute request

Thank you!

Well, this all works now! It’s actually quite fast.

Talking about backgroundrb: I’d like to do a few whois requests every
night for another application and I’m using Ruby’s Whois for that
( I cannot use that class inside a
worker. For that to work, I need to create an object for that class in
my controller and send it to my worker using a MiddleMan. However,
that’s not how I want to do it, because I want to schedule this using
my backgroundrb.yml. What am I doing wrong? require ‘whois’ in my
worker or environment.rb won’t work. Am I overlooking something?

Thank you?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs