2

I'm using rails 3, eventmachine and rabbitmq.

When I publish message(s) to a queue, I need to launch multiple worker processes.

I understand that eventmachine is solution for my scenerio.

Some tasks will take longer than others.

Using eventmachine, from most code samples it looks like only a single thread/process will be run at any given time.

How can I launch 2-4 worker processes at a single time?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • appears that you can't start more than one EM instance, at least... http://stackoverflow.com/questions/8247691/multiple-ruby-eventmachines-in-one-process-possible – rogerdpack Jan 02 '14 at 22:39

1 Answers1

4

if you use the EM.defer method every proc you pass to it will be put in the thread pool (default to 20 threads). you can have as many worker you want if you change the EM.threadpool_size.

worker = Proc.new do
# log running job
end

EM.defer(worker)
ALoR
  • 4,904
  • 2
  • 23
  • 25
  • thanks, ok so I write to the queue in my rails app. Regarding this codesnippet, I would put this in the start process and then EM will create 20 threads that will run the 'worker' method? – Blankman Mar 23 '11 at 21:34
  • yes, just keep in mind that if you use EM for other tasks, the 20 thread are shared between the workers an the tasks. EM has an internal pool of threads used for everything. i suggest you to dig into the manual of EM regarding the deferrables. – ALoR Mar 23 '11 at 21:58