RxNetty icon indicating copy to clipboard operation
RxNetty copied to clipboard

RxNetty and Hystrix Request Caching

Open dfjones opened this issue 9 years ago • 4 comments

I'm curious if anyone has any experience/advice with the combination of RxNetty and Hystrix request caching.

The default Concurrency Strategy for Hystrix seems a bit at odds with the concurrency model of RxNetty (or anything async). I've noticed some hooks in Hystrix to try and populate context to child threads, but the issue I'm seeing is a pollution of these contexts on the Netty IO threads. Hystrix's AbstractCommand has this hooks in this method to carry the context forward:

 private static void setRequestContextIfNeeded(final HystrixRequestContext currentRequestContext) {
        if (!HystrixRequestContext.isCurrentThreadInitialized()) {
            // even if the user Observable doesn't have context we want it set for chained operators
            HystrixRequestContext.setContextOnCurrentThread(currentRequestContext);
        }
    }

However, there doesn't appear to be anything to reset the context before the Netty thread is returned to the pool.

For short lived caching that could be shared across requests, this might be ok, however, if we want to use this context for data that should only be available on a single request, it seems like this behavior would potentially contaminate other requests.

So, what do RxNetty and Hystrix users do to get around this?

dfjones avatar Jun 24 '16 17:06 dfjones

@dfjones is this for 0.4.x or 0.5.x branch?

NiteshKant avatar Jun 27 '16 01:06 NiteshKant

@NiteshKant 0.4.x branch

dfjones avatar Jun 27 '16 14:06 dfjones

@dfjones have you looked at the rxnetty-contexts module for 0.4.x? It can be used for request specific caching.

NiteshKant avatar Jul 01 '16 02:07 NiteshKant

@NiteshKant No! I wasn't aware of that module. I'll give it a shot, thanks!

dfjones avatar Jul 01 '16 18:07 dfjones