danielfm / pybreaker

Python implementation of the Circuit Breaker pattern.
BSD 3-Clause "New" or "Revised" License
512 stars 74 forks source link

thread safety ? #3

Closed gst closed 5 years ago

gst commented 9 years ago

Hi,

not an issue but a question:

is it safe to use the same breaker instance (CircuitBreaker) by multiple threads, possibly concurrently (modulo GIL ofcourse) ?

thx for the lib :)

gst commented 9 years ago

I answer to myself :

given a circuit breaker is associated with a thread lock and that the lock is taken whenever a call is done on/with the circuit breaker then yes it's safe to use the same breaker instance with multiple threads, concurrently running.

But then any combination of threads using the same circuit will be limited by this : only one "call" at a time will be processed given this lock.

But what if we don't want this behavior but still want to use/share the same breaker between multiple threads ?

I'm thinking : there could simply be a lock-less version of the circuit breaker.. which could be the "base" one, and the lock version of the circuit breaker would simply subclass the lock-less version and add the lock and use it..

wdyt?

danielfm commented 9 years ago

Yes, I think that's a great idea!

On Mon, Jul 20, 2015, 10:58 AM Grégory Starck notifications@github.com wrote:

I answer to myself :

given a circuit breaker is associated with a thread lock and that the lock is taken whenever a call is done on/with the circuit breaker then yes it's safe to use the same breaker instance with multiple threads, concurrently running.

But then any combination of threads using the same circuit will be limited by this : only one "call" at a time will be processed given this lock.

But what if we don't want this behavior but still want to use/share the same breaker between multiple threads ?

I'm thinking : there could simply be a lock-less version of the circuit breaker.. which could be the "base" one, and the lock version of the circuit breaker would simply subclass the lock-less version and add the lock and use it..

wdyt?

— Reply to this email directly or view it on GitHub https://github.com/danielfm/pybreaker/issues/3#issuecomment-122893931.

gst commented 9 years ago

I've think again about it : probably the lock should still be more than necessary (for the circuit breaker failure count), but it's not necessary to have it locked while you actually call/execute the "wrapped" function..

gst commented 9 years ago

the next step would be to propose a PR I guess ;)

danielfm commented 9 years ago

That would be nice! :smile:

robertlagrant commented 5 years ago

@gst @danielfm did this get any further?

gst commented 5 years ago

not on my side sorry. not anymore user of pybreaker.