How to block caller using Hystrix Synchronous Queue

234 views
Skip to first unread message

Monmohan Singh

unread,
Mar 15, 2017, 11:40:13 PM3/15/17
to HystrixOSS
Hi,
I am trying to implement the following scenario -
  1. Have a Hystrix Command , which can take time to run
  2. Multiple callers (threads) can call this command
  3. If all the threads in the Hystrix thread pool are busy running the command, I would like the caller to block
  4. Reading the documentation says -

maxQueueSize

This property sets the maximum queue size of the BlockingQueue implementation.

If you set this to -1 then SynchronousQueue will be used, otherwise a positive value will be used with LinkedBlockingQueue.


So I set maxQueueSize to -1 and expect that if there is no thread to remove the job from queue, the caller would block. Instead Hystrix throws RejectedExecutionException. How can I configure this behavior to instead have the caller blocked?


Thanks

Monmohan

Monmohan Singh

unread,
Mar 16, 2017, 10:56:34 AM3/16/17
to HystrixOSS
[Update]
After reading the documentation more carefully, I think this is the intended behavior.
In order to keep the calling application responsive, Hystrix would want to fail if all threads in the pool are busy making the request to the external service (bulk head pattern).
Looks like Hystrix is not the right solution for my case (or perhaps there is a way). 
I was using Hystrix mainly to utilize "walk away on timeout" but wanted to throttle the upstream caller if all threads were busy.

Regards
Monmohan

Matt Jacobs

unread,
Mar 20, 2017, 5:15:34 PM3/20/17
to HystrixOSS
Monmohan - Your second post is exactly right.  Hystrix is intended to be used in the case where it's more important for the application to provide a bounded worst-case than to allow all work to always complete.  

What you're talking about sounds a lot like backpressure (you want a fast producer to slow done in the presence of a slow consumer).  This has been an area of innovation in a lot of different projects.  You may wish to look at some of the options discussed here: http://www.reactive-streams.org/
Reply all
Reply to author
Forward
0 new messages