Event loop context?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Event loop context?

dedee
Hi :)

I want to do some kind of processing of request/response inside Context. Processing is being done by instance of, let's call it - Processor class. The thing is, that instantiation of Processor is rather costly (xslt engine) and doing so every time request arrives is out of question. I'd like to avoid making Processor class thread safe using synchronization primitives (and creating a bottleneck) or doing some object pooling. What I'd like to do is create an instance of Processor per event loop during bootstrap of my app. So is there any kind of event-loop-context where I can put objects (thread-locals abstraction)?
Reply | Threaded
Open this post in threaded view
|

Re: Event loop context?

Luke Daley
Administrator
Interesting question.

You could use plain old thread locals, if you are going to use the object within a single execution segment. That is, you can use it without needing to do anything async and therefore relinquish the thread. If you can’t guarantee that, then your next best option is to use an object pool. Netty provides quite a good one in http://netty.io/4.1/api/io/netty/util/Recycler.html.

If you are going to use thread locals, you can use Netty’s http://netty.io/4.1/api/io/netty/util/concurrent/FastThreadLocal.html.

Some other ideas come to mind, but I’d start with those.