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|
Thread.new do
executor(collection)
sleep sleeptime
end
end
end
def executor
#execute request
end
end
Thank you!
On 26 okt, 12:21, jhaagmans <[email protected]> wrote:
> Hi,
>
> I'd like to make a few requests per second to another method using,
> for example, backgroundrb (any other suggestions are welcome as
> well!).
>
> 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
> milliseconds.
>
> I hope you can help. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---