Ok I'm doing some testing with Stalker and Beanstalkd. My objective is to offload 500kb post requests to queue and process them asynchronously.
So far in my testing I have this very simple example.
#worker.rb
require 'stalker'
include Stalker
job 'hello' do |args|
puts "hi"
sleep 1
puts "hello"
end
and this file for adding to queue
# stalker.rb
require 'rubygems'
require 'stalker'
10.times do
Stalker.enqueue('hello')
puts 'queued'
end
So in one terminal I run
$ stalk worker.rb
Working 1 jobs: [ hello ]
Then I run the stalker file
$ ruby stalker.rb
stalker executes almost instantly as expected so no blocking on that.
but the worker takes approximately 10 seconds to run. Really I want this to be much closer to 1 second for those 10 jobs because I want them to run in parallel.
Any recommendations on the next best step to do this?
UPDATE: I've realised I can run multiple workers from different terminals and it will process the queue much faster e.g. 2 workers will do the process in roughly half the time.