Re: [patch 00/13] Syslets, "Threadlets", generic AIO support, v3

Davide Libenzi
2007-02-26T20:02:57Z

On Mon, 26 Feb 2007, Ingo Molnar wrote:

>
> * Ingo Molnar <mingo@elte.hu> wrote:
>
> > please also try evserver_epoll_threadlet.c that i've attached below -
> > it uses epoll as the main event mechanism but does threadlets for
> > request handling.
>
> find updated code below - your evserver_epoll.c spuriously missed event
> edges - so i changed it back to level-triggered. While that is not as
> fast as edge-triggered, it does not result in spurious hangs and
> workflow 'hickups' during the test.
>
> Could this be the reason why in your testing kevents outperformed epoll?

This is how I handle a read (write/accept/connect, same thing) inside
coronet (coroutine+epoll async library - http://www.xmailserver.org/coronet-lib.html ).

static int conet_read_ll(struct sk_conn *conn, char *buf, int nbyte) {
int n;

while ((n = read(conn->sfd, buf, nbyte)) < 0) {
if (errno == EINTR)
continue;
if (errno != EAGAIN && errno != EWOULDBLOCK)
return -1;
if (!(conn->events & EPOLLIN)) {
conn->events = EPOLLIN;
if (conet_mod_conn(conn, conn->events) < 0)
return -1;
}
if (conet_yield(conn) < 0)
return -1;
}

return n;
}

I use EPOLLET and, you don't change the interest set until you actually
get an EAGAIN. *Many* read/write mode changes in the usage will simply
happen w/out an epoll_ctl() needed. The conet_mod_conn() function does the
actual epoll_ctl() and add EPOLLET to the specified event set. The
conet_yield() function end up calling the libpcl's co_resume(), that is
basically a switch-to-next-coroutine-until-fd-becomes-ready (maps
directly to a swapcontext).
That cuts 50+% of the epoll_ctl(EPOLL_CTL_MOD).

- Davide