Blankman
Blankman

Reputation: 267390

How to launch multiple worker processes in eventmachine?

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?

Upvotes: 2

Views: 2011

Answers (1)

ALoR
ALoR

Reputation: 4914

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)

Upvotes: 4

Related Questions