On Friday, December 18, 2015 at 6:25:22 PM UTC-8, Mike Pastore wrote:
>
> Hi folks,
>
> I have a single Sequel connection (held by a class ivar) that is being 
> shared between multiple threads. I'd like to implement the multiple 
> read-only slave pattern[1] but I'm concerned that multiple threads will be 
> calling the round-robin proc simultaneously, leading to either poor 
> performance due to the GIL or data corruption. Is there a simple way to 
> make the proc thread-safe or is there another strategy I can employ? Or am 
> I being overly cautious? :-) 
>
> I'm running Puma workers+threads under MRI at the moment but looking to 
> move to JRuby in the future.
>
> Thank you in advance,
>
> Mike
>
> 1. 
> http://sequel.jeremyevans.net/rdoc/files/doc/sharding_rdoc.html#label-Multiple+Read-Only+Slaves-2C+Single+Master
>

 If you are really concerned about it, you can always use a mutex inside 
the proc.  But I wouldn't worry about it.  The proc is only called when a 
new connection is needed, which should be infrequent in most production 
applications as the connections are cached.  The worst case scenario is 
that two threads would connect to the same backend, but assuming the number 
of simultaneous connections you are allowing is greater than the number of 
read only-slaves (true in most cases), that's going to be be true anyway.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to