This is the patch in question, it is simple, reduces latency *a lot* (and improves pgsql.pike performance by a factor of 2 or so; I could imagine the boost is similar in other I/O-type of applications):
From 7601bd31847562755a1688a99aa2bdc2a340414f Mon Sep 17 00:00:00 2001
From: Stephen R. van den Berg srb@cuci.nl Date: Sat, 26 Jul 2008 12:51:23 +0200 Subject: Decrease latency in zero-timeout polls/selects
--- src/modules/files/file.c | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/modules/files/file.c b/src/modules/files/file.c index 6daf5c3..a3e830e 100644 --- a/src/modules/files/file.c +++ b/src/modules/files/file.c @@ -844,14 +844,17 @@ static void file_peek(INT32 args) struct pollfd fds; int timeout; timeout = (int)(tf*1000); /* ignore overflow for now */ - if (!timeout) timeout = 1; fds.fd=FD; fds.events=POLLIN; fds.revents=0;
- THREADS_ALLOW(); - ret=poll(&fds, 1, timeout); - THREADS_DISALLOW(); + if(timeout) { + THREADS_ALLOW(); + ret=poll(&fds, 1, timeout); + THREADS_DISALLOW(); + } + else + ret=poll(&fds, 1, 0);
if(ret < 0) { @@ -876,8 +879,6 @@ static void file_peek(INT32 args) fd_set tmp; struct timeval tv;
- tv.tv_usec=1; - tv.tv_sec=0; fd_FD_ZERO(&tmp); fd_FD_SET(FD, &tmp); ret = FD; @@ -887,9 +888,13 @@ static void file_peek(INT32 args)
/* FIXME: Handling of EOF and not_eof */
- THREADS_ALLOW(); - ret = fd_select(ret+1,&tmp,0,0,&tv); - THREADS_DISALLOW(); + if(tv.tv_sec || tv.tv_usec) { + THREADS_ALLOW(); + ret = fd_select(ret+1,&tmp,0,0,&tv); + THREADS_DISALLOW(); + } + else + ret = fd_select(ret+1,&tmp,0,0,&tv);
if(ret < 0) {