crate_ruby icon indicating copy to clipboard operation
crate_ruby copied to clipboard

Use multiple connections

Open wnkz opened this issue 9 years ago • 2 comments

Hey, At the moment, this gem only uses the first server from the array we pass, I think it would be very useful to use all of them because sometime under heavy load or when running a lot of request in a short duration, queries ended up failing. I think it's not because the cluster cannot process the request but simply because of HTTP requests saturation.

I'm willing to work on a patch for this but I'd like your approval first ; mostly to know if it's recommended to run queries directly on secondary nodes while queries are running on the primary. I'm pretty sure it works, but I'm not sure it's recommended.

What I have in mind right now (didn't start coding anything):

  • Retry on a different server if request fails
  • Simple load balancing (round roaming)
  • (Maybe) Advanced load balancing depending on the individual load of each node of the cluster (if possible)

Let me know what you think, Cheers,

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

wnkz avatar May 11 '15 16:05 wnkz

hi @wnkz

indeed, the client should use multiple hosts for failover scenarios. the best way to implement that is round robin "load balancing". you can perform any query on any node of the cluster. using multiple hosts for queries helps to reduce load on each of the handler nodes.

if you start implementing it, you can take a look at the python client first, where this is implemented in a clean way: https://github.com/crate/crate-python/blob/master/src/crate/client/http.py#L279 I think the code is more or less self explanatory, but if you have any questions, please ask again :)

chaudum avatar May 12 '15 06:05 chaudum

What do you think about using https://github.com/mperham/connection_pool ?

wnkz avatar Jun 24 '15 11:06 wnkz