pistachio is an HTTP long polling middleware for Rack:
Need events delivered to an HTTP client in realtime? Perhaps youve
investigated solutions like Comet/Bayeux, BOSH, or WebSockets. Not happy
with those solutions and just want something simple? Pistachio provides
simple HTTP long polling middleware for Rack. Pistachio provides
similar functionality to the nginx_http_push_module (
The middleware exposes a very simple HTTP-based protocol for performing
polling of Redis’s ordered lists:
- HTTP 200 means an item was successfully popped from the list
- HTTP 504 means the long polling request to Redis (in the form of a
BLPOP") timed out and should be retried
- Anything else is an error
Pistachio uses named channels with unique IDs to route messages. Support
sessions is not (yet) provided, nor is user-provided dispatching logic.
Instead a client just long polls a particular channel ID, popping any
messages that are available or blocking until a specified timeout if
aren’t. Pubsub support forthcoming…
The path to mount the middleware and the long polling timeout are fully
configurable. And unlike the nginx_http_push_module, you won’t need to
recompile nginx to use it.
Pistachio will gain support for distribution and failover following the
release of Redis Cluster. See:
Pistachio is built on the Stash library, which provides an abstract
interface to servers like Redis. In theory, it would be possible to use
other servers which provide the same properties as Redis’s lists as the
backend, such as the Kestrel message queue. More information on Stash is
SUPER SHORT Q&A!
Q: Does it ROFLSCALE with Fibers and EventMachine?
A: No, Pistachio does not ROFLSCALE. The current implementation is naive
simple. Pistachio opens a new connection to Redis whenever it services a
request, and that connection is closed whenever the request completes.
Concurrency is provided by threads. This could become a problem if you
expect large numbers of concurrent clients and don’t want to run large
numbers of web servers.
Pistachio COULD easily ROFLSCALE using libraries like Rainbows!,
and em-redis, or even something with Node.js. However, this is
until Redis Cluster actually works.