users@grizzly.java.net

Re: Async Writes & recommendations

From: Robert Greig <robert.j.greig_at_gmail.com>
Date: Thu, 14 Jun 2007 09:07:16 +0100

On 13/06/07, Jeanfrancois Arcand <Jeanfrancois.Arcand_at_sun.com> wrote:

> Robert, I still need to look at your code, but are you using a queue
> with a dedicated thread pool for OP_WRITE or a second Selector (or
> something completely different?)

For each reader thread, we have a second thread doing writes, and a
second Selector used for OP_WRITE. A given thread (and selector) is
responsible for multiple sessions. There is a separate queue of
sessions that have data to flush (from which the writer thread pulls
off sessions).

IIRC we have logically something like this:

forever
{
while (getSessionWithDataToFlush from queue of sessions)
{
    write out data from session up to a "fairness" maximum of say 512k
    if kernel buffer fills up, register interest in OP_WRITE
    if kernel buffer hasn't filled up but we have still got data to
write out, put the session back on the queue
}
selector.select, and add any sessions to the queue of sessions which
can write out at least one byte
}

RG