Unix Programming - epoll waits for entire timeout

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2006 > epoll waits for entire timeout





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author epoll waits for entire timeout
simon@arrowtheory.com

2006-09-25, 7:35 pm


I have a single-threaded client reading/writing on two sockets, using
epoll.
Maybe I made a trivial error, but it looks like epoll always waits for
the entire time specified by the timeout parameter, weather or not
there is data ready for read/write.
I'm going a bit nutty staring at strace's (i also have a multi-threaded
version that works properly)
trying to figure out if there's a flag somewhere i need to set.

thanks for any help,

Simon.

Michael Kerrisk

2006-09-26, 1:48 am

On 25 Sep 2006 11:37:36 -0700, simon@arrowtheory.com wrote:

>
>I have a single-threaded client reading/writing on two sockets, using
>epoll.
>Maybe I made a trivial error, but it looks like epoll always waits for
>the entire time specified by the timeout parameter, weather or not
>there is data ready for read/write.
>I'm going a bit nutty staring at strace's (i also have a multi-threaded
>version that works properly)
>trying to figure out if there's a flag somewhere i need to set.


This sounds like a bug in your program. Can you post the smallest,
complete example demonstrating the problem.

Cheers,

Michael
simon@arrowtheory.com

2006-09-26, 1:22 pm


Michael Kerrisk wrote:
....
> This sounds like a bug in your program. Can you post the smallest,
> complete example demonstrating the problem.
>
> Cheers,
>
> Michael


Yes it does sound like a bug. Unfortunately the code is rather massive
and
dispersed. Small examples that i have written work fine.

I have gone over the epoll_* calls again and again, using strace and
print statments. And so far it all looks good.

However, there is a little more information i have found. That
epoll_wait *does* in fact timeout quickly (with events), but almost
always *after* an entire wait (waiting for the entire <timeout>
milliseconds, usually yielding no events). So the network profile makes
it *look* like epoll_wait waited for the entire time, yielding with
events.

Well, it's putting hairs on my chest. (I was looking at the linux
kernel code yesterday.)

thanks for your help,

Simon.

William Ahern

2006-09-26, 7:28 pm

On Mon, 25 Sep 2006 11:37:36 -0700, simon wrote:

>
> I have a single-threaded client reading/writing on two sockets, using
> epoll.
> Maybe I made a trivial error, but it looks like epoll always waits for the
> entire time specified by the timeout parameter, weather or not there is
> data ready for read/write.
> I'm going a bit nutty staring at strace's (i also have a multi-threaded
> version that works properly)
> trying to figure out if there's a flag somewhere i need to set.
>


Are you using the edge-triggered or level-triggered epoll option? The
behavior you describe could be caused by using edge-triggered polling.

simon@arrowtheory.com

2006-09-26, 7:28 pm


William Ahern wrote:
....
>
> Are you using the edge-triggered or level-triggered epoll option? The
> behavior you describe could be caused by using edge-triggered polling.


I don't use the EPOLLET flag. Here is a dump of the epoll calls from
strace:

epoll_create(128) = 3
....
epoll_ctl(3, EPOLL_CTL_ADD, 5, {EPOLLIN|EPOLLPRI, {u32=5,
u64=13232057892602904581}}) = 0
epoll_ctl(3, EPOLL_CTL_MOD, 5, {EPOLLIN|EPOLLPRI|EPOLLOUT, {u32=5,
u64=13232057308487352325}}) = 0
epoll_wait(3, {{EPOLLOUT, {u32=5, u64=13232057308487352325}}}, 1, 100)
= 1
....

Simon.

James Antill

2006-09-27, 1:21 pm


On Tue, 26 Sep 2006 13:15:53 -0700, simon wrote:

>
> William Ahern wrote:
> ...
>
> I don't use the EPOLLET flag. Here is a dump of the epoll calls from
> strace:


Your timeout is 100 milliseconds, this indicates something is less than
good (to me) ... you should be able to wait for longer than that. It also
explains your problem if you have a 10Hz kernel or (more likely) you hit
some weird latency problem that stops the wakeup.

> epoll_create(128) = 3
> ...
> epoll_ctl(3, EPOLL_CTL_ADD, 5, {EPOLLIN|EPOLLPRI, {u32=5,
> u64=13232057892602904581}}) = 0
> epoll_ctl(3, EPOLL_CTL_MOD, 5, {EPOLLIN|EPOLLPRI|EPOLLOUT, {u32=5,
> u64=13232057308487352325}}) = 0
> epoll_wait(3, {{EPOLLOUT, {u32=5, u64=13232057308487352325}}}, 1, 100)
> = 1
> ...


If that doesn't help, showing a bigger strace with -tt would give more
info. I'd also suggest you look at code which uses epoll (and-httpd,
lighttpd and libevent come to mind).

--
James Antill -- james@and.org
http://www.and.org/and-httpd

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com