I have a server implemented in netty that processes a user request, talks to middleware and sends a response. The I / O is expected to be negligible compared to the middleware call, so to minimize the lock, I have an ExecutionHandler in the pipeline on top of the OrderedMemoryAwareThreadPoolExecutor. There are no problems at the moment.
I learn how the server behaves under heavy load. From past experience with our protocol, we are usually overwhelmed with random DOS attacks - most often the user of the script gets stuck in an infinite loop or similar. Ideally, we could turn off the priority of our channels after they pass a certain threshold of use, so that the service of other users will not be affected.
I implemented a simple ThreadPoolExecutor that uses PriorityBlockingQueue and sets priority based on data retrieved from our own Session class (context bound in ChannelHandler). Again, no problem yet.
The difficulty arises when you try to take advantage of the ordering and memory of the Netty elements built into ThreadPoolExecutors. Ideally, MyThreadPoolExecutor can simply extend OrderedMemoryAwareThreadPoolExecutor and spill priority queues into the material. Alas, this is impossible for two reasons: private and final. More details:
a) ThreadPoolExecutor.workQueue can be set in its constructor, but MemoryAwareThreadPoolExecutor hardcodes it as a LinkedTransferQueue and does not provide it to the child node OrderedMemoryAwareThreadPoolExecutor (i.e. MyThreadPoolExecutor does not have access to configure it). If necessary, this can be overcome with the ugly bit of the private field setting based on reflection.
b) MyThreadPoolExecutor.doUnorderedExecute(), , . , , .
, , , "" "OrderedMemoryAwareThreadPoolExecutor", "MemoryAwareThreadPoolExecutor", , . ! , .
:
1) ? , ?
2) , , , ?
3). - , . "" , , , , . , ? ( .)
4) , . - OrderedMemoryAwareThreadPoolExecutor X Y - , ThreadPoolExecutor, -? , . , ExecutionHandler, - - , ExecutionHandler? , ExecutionHandler, ? , , Thread X MemoryAwareThreadPoolExecutor 2 1 - , , , ( workQueue). ExecutionHandler , .
, .