Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrency strategy wrapCallable method being called twice #1548

Closed
patrick-s7 opened this issue Apr 25, 2017 · 3 comments
Closed

Concurrency strategy wrapCallable method being called twice #1548

patrick-s7 opened this issue Apr 25, 2017 · 3 comments

Comments

@patrick-s7
Copy link

When creating and registering a custom HystrixConcurrencyStrategy, I noticed two things.

  1. For semaphore based calls, wrapCallable() is getting called once, but the wrapped callable's call() method is never getting called.
  2. For thread based calls, wrapCallable() is getting called twice, but the wrapped callable's call() method is only getting invoked on the second wrapped callable.

I've attached a simple maven project (hopefully boiled down enough) that uses print statements to highlight these calls as well as some of the other interesting events that occur in both a semaphore based call and a thread based call.

My concern is that calling wrapCallable twice for thread based calls makes it more difficult to manage internal state because the strategy is not sure which call they're on, or if the wrapped callable they're creating is actually going to get called or not.

Also, from a performance perspective, it seems unnecessary to call wrapCallable if the resulting wrapped callable won't be used.

hystrix-concurrency.zip

@mattrjacobs
Copy link
Contributor

Thanks for the report, @patrick-s7 !

For thread-isolation, the 2 places where wrapCallable are being invoked today are:

  1. https://github.com/Netflix/Hystrix/blob/master/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java#L106, which puts the user work on a Hystrix thread-pool and gives it the calling thread's context.

  2. https://github.com/Netflix/Hystrix/blob/master/hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java#L1138, which sets up a runnable to be executed only upon timeout. This runnable also requires the calling thread's context

For semaphore-isolation, only the 2nd is occurring.

I believe that there's an optimization to be done here to only create the HystrixContextRunnable for the timeout-handler if a timeout actually occurs. I'll investigate that.

@patrick-s7
Copy link
Author

@mattrjacobs I just saw that you closed this out. Thank you for addressing this. My apologies for not commenting sooner.

@mattrjacobs
Copy link
Contributor

No problem - thanks again for the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants