Daniel John Debrunner wrote:

I'm seeing hangs when I use an IoEventQueueThrottle as below. I read the comments in the javadoc about requiring an executor in the filter chain. I get no hangs if I do not add "writeThrottle" into the chain (my app is currently throttling by waiting for every 100th write to complete).

// Setup
NioSocketConnector connector = new NioSocketConnector();
connector.getFilterChain().addFirst("executor", new ExecutorFilter(1));
connector.getFilterChain().addLast("writeThrottle",
    new WriteRequestFilter(new IoEventQueueThrottle(10)));


// message sennding

IoBuffer buf = prepareBuffer();

WriteFuture wf = session.write(buf);

Are there any examples of how to use IoEventQueueThrottle for write throttling?

The problem is that you probably have a slow client. Even if you use a throttling mechanism, you will block one thread until all the write is done.

By using an executor, the writes are put into a queue, and the thread is freed, and able to accept another client interaction.

Now, if you have many slow clients, at some point, the executor will become a bottleneck. Also you can quickly saturate the memory if you are writing huge messages to slow clients, as they will remain in the queue for a long time.

A way to manage this is to split the message in small chunks (say, 1kb), and wait until the selector is ready for the next submission. Alas, you don't have a hand on the selector, but you can manage the MessageSent event. So if your application, you split your message in small parts, manage the MessageSent event, deal with the overhead, add an executor, you can handle any kind of scenario, including a DOS by slow reader (you will just have to set a timeout or manage idleconnection)

That would be good for sure to have such a mechanism implemented in MINA... This is not exactly what does the IoEventQueueThrottler : it does limit the size of data sent to the client to a certain size, limiting the throughput. Probably not what you want.

Hope it helps

Thanks,
Dan.



--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to