Ruby eventmachine async client

Mathias Meyer meyer at paperplanes.de
Fri Mar 16 06:52:16 EDT 2012


Hey Sean,

for a while I hacked on an EM-based Riak client but didn't find the time to investigate it further.

So you can do several things with riak-ruby-client an EM:

1) Just use the client with EM.defer, putting it into other threads. That arguably voids the purpose of using EM, but at least defers the blocking I/O work to a pool of threads where it can be handled without blocking the reactor.
2) Write a backend for riak-ruby-client that utilizes em-synchrony and em-http to turn things into a more procedural workflow. That should be simple enough based on the net/http backend [1]. Be aware of the limitations of using fibers though, their stacks only fit 4K so keep your stacks small :)
3) You could also just use em-http-request, but that way you'd give up a lot of functionality that's already in riak-ruby-client.

I'd recommend looking at #2, it looks like an easy path and should make for a great addition to the riak-ruby-client too. In my ideal world, there'd be a backend based on Faraday [2], so that the Ruby client wouldn't even have to worry about the underlying implementation, but you need to punch Sean Cribbs (very nicely) about that. Or you could just use Faraday instead of em-synchrony all along, since Faraday has a backend for em-http/synchrony already.

Hope this helps.

Cheers, Mathias
http://riakhandbook.com

[1]: https://github.com/basho/riak-ruby-client/blob/master/lib/riak/client/net_http_backend.rb
[2]: https://github.com/technoweenie/faraday





On Friday, 16. March 2012 at 05:39, Sean McKibben wrote:

> Given Mathias Meyer's talk at Scotland Ruby Conference about eventmachine programming (while wearing a Riak t-shirt!), I was hoping to see a little bit more in terms of eventmachine clients and Riak.
> 
> Has anyone used EventMachine and/or em-synchrony with Riak and could give me some advice? I'm using ruby-riak-client at this point and going the route of trying to wrap my workflow in fibers so riak client plays nice with it.
> 
> Am I better off just using a HTTP client like EM::HttpRequest or EM::Synchrony::Multi, or is there some good way to use ruby-riak-client or ripple with eventmachine that requires less manual intervention?
> 
> Sorry if this has been covered somewhere else but I haven't had much luck finding anyone else using EM with Riak.
> 
> Thanks,
> Sean McKibben
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com (mailto:riak-users at lists.basho.com)
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com







More information about the riak-users mailing list