Preserving channel events order without using an ExecutionHandler

ljohnston johnstlr at yahoo.co.uk
Fri Nov 5 14:06:41 EDT 2010


I know this is a bit after the fact but...

You can just pass a normal executor to the NioServerSocketChannelFactory.
Executors.newCachedThreadPool tends to be the norm.

Each ServerSocketChannel is processed exclusively by one thread from the
boss executor. This guarantees the event ordering on the server socket
channel.

Netty uses N threads from the worker executor where, in your example, N is
workerCount. Accepted socket channels are load balanced across the N threads
in a round robin fashion, so a socket channel is only ever processed by one
thread. Again this guarantees event ordering.

The OrderedMemoryAwareThreadPoolExecutor is a thread pool that also
guarantees event ordering. Most executors have a single, shared queue that
is processed by the threads in parallel but in a non-deterministic order.
The OrderedMemoryAwareThreadPoolExecutor effectively has a queue per channel
and each queue can only be processed by a single thread at any given time
thus guaranteeing event order.

If your code is completely non-blocking, don't use any kind of executor. If
you set workerCount appropriately you'll only ever be processing a maximum
of workerCount messages at a given time and you can use
channel.setReadable(false) to throttle any given channel - take a look at
the proxy server and discard examples.

Cheers
Lee
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Preserving-channel-events-order-without-using-an-ExecutionHandler-tp5689124p5710083.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list