Reputation: 19
I want to understand how netty worker threads work . as per the code , for each new request we get nextwoker() any one of the worker thread and allocate it for processing of events of client . SO a single thread will be able to handle different request from different clients as per my understanding .
I have one question here whether for client(channel/socket) all the events coming in that particular channel are handled by the same thread or can different threads can handle them . My assumption is single thread handles all events (excluding Future events) . But as per the documentation of MemoryAwareThreadPoolExecutor they tell that for a channel - different threads handle different events .
To verify this i wrote a small program using a single client and worker threadppol which has 50 worker threads but when i keep sleep in message received event , my client waits for next message received call . which confirms that single thread per client is allocated . Please clarify ...
Upvotes: 0
Views: 2792
Reputation: 9284
I think it's only safe to assume that the same thread will not be used for the same client.
Upvotes: 0
Reputation: 23557
The same Worker thread will be used for the Channel all the time. So its safe to asume thats the case.
If you use a OrderedMemoryAwareThreadPoolExecutor this may not be the case anymore.
Upvotes: 2
Reputation: 2388
From my understanding, Netty uses worker threads to handle incoming connections.
You should not block (sleep in) these worker threads otherwise your clients will be waiting for a response and you will also waste a thread that could have been used for process another request.
What you should do is to dispatch your work to another thread pool using OrderedMemoryAwareThreadPoolExecutore; or you can do it using your own Executor in messageReceived()
.
Upvotes: 0