Skip to content

Instantly share code, notes, and snippets.

@rehanift
Created November 24, 2011 21:43
Show Gist options
  • Save rehanift/1392360 to your computer and use it in GitHub Desktop.
Save rehanift/1392360 to your computer and use it in GitHub Desktop.
Integrating 0mq w/ EventMachine into a rails application
* Rack
- Rack::FiberPool provides a Fiber for each request
* Application Server
- Thin: starts its own EM reactor
- Passenger: Start a new reactor in a new thread
- Other: Start a new reactor in a new thread
* Rails
- initialzier: Start a new EM reactor (depending on app server)
* Code
- questions:
- At this point, how do we use the existing EM reactor? There is
already a thread with an EM reactor loop running.
- Every app process needs a EM thread. The EM thread is an event loop.
- When code makes an blocking call it falls back to the event
loop and lets another Fiber resume.
- That shits gonna block *within* the Fiber-wrapped rails request
- em-zeromq manipulates the file descriptor associated with the socket
- 0mq does it magic
- em-zeromq watches fd associated with the socket. When there is
activity it is reported back to em-zeromq (how?)
* Goal
- Make a 0mq request and wait for a response with an rails request
* Test
- Use thin + Rack/Fiber-Pool + EM-ZMQ
- Push & Subscribe with 0mq
- Push should not block
- Subscribe should block until a message is received
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment