Using Circuit breaker pattern in Multi Threaded Environment

Multi tool use
Multi tool use


Using Circuit breaker pattern in Multi Threaded Environment



I am working on project which fetches the data from the REST API using C#. I am calling this in multi threaded fashion in a batch of 100 records at a time using Parallel.ForEach. I want to use a circuit breaker pattern when 2 requests in the 100 were failed due to connectivity error.


REST API


C#


Parallel.ForEach



I have checked the Poly Framework but did not get concrete examples of using the fault tolerant circuit breaker pattern in multi threaded scenarios(May I am missing those).



Any examples and frameworks to achieve this?
Any links for achieving this would bee very helpful.





All these fancy patterns!, for starters Parallel.ForEach shouldn't be used for IO bound operations. you are wasting resources and tying up threads. Secondly, Parallel.ForEach has no concept of a timeout (Circuit break pattern is now dead in the water), all you can do is use some sort of thread safe switch to shirt circuit residual processing. For thirds, you cant cancel a task that is not cancellation-aware (term i may have just made up) so what ever you are using hopefully should have a time out. lastly,
– TheGeneral
Jul 3 at 6:32



Parallel.ForEach


Parallel.ForEach


timeout





Thanks for the inputs @TheGeneral. I am hoping it should break even for any connectivity error. This should not specific to only time out.
– Mahesh Biradar
Jul 3 at 6:45





You can spin up and start your own Tasks in a for loop. Tasks can be cancelled, and you can cancel them all if one or more Tasks fail in a certain way.
– MineR
Jul 3 at 7:07





I was able to cancel the tasks and proceed as mentioned by MineR, But I have done the performance analysis of my code in the server and found that as TheGeneral mentioned it in comments it was indeed consuming quite a bit resources. So I have changed the code to call async and utilized the Polly's circuit breaker pattern on top of. Thanks for all the comments.
– Mahesh Biradar
Jul 6 at 6:05









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

yDSGVZD,xR8,lzwuSVVzB02j yobRo49TFCc4o f4ay,kGpYB,Hi 9TQqJnUaplcX4
bc0iZT71h2,I,mqCVQD2,c97zu4O0tgiyzpD5NBg,znwuPN1m pJLKki7scEK3,hgZ Uzmk At2LL,i2vP2X7PBe,fbYS

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications