From a9c45135e5c24155bb3260b27eb6d346c4e2197d Mon Sep 17 00:00:00 2001 From: "K. Noel Belcourt" Date: Sat, 20 Nov 2010 00:15:41 +0000 Subject: [PATCH] Fix poor parallel throughput on larger SMP systems. When select() returns with data on one or more file descriptors, we use fread() to read data from the live descriptors. The problem is that these are blocking file descriptors so most of the time bjam is waiting, it's actually waiting in fread(), rather than waiting in select(). There are two possible patches: one is to just call fread() a single time (not inside a loop) or we can make the file descriptors non- blocking. It's more efficient to make the descriptors non-blocking as this allows us to read all data on a descriptor each time select() returns. The first approach would not permit us to read all the data on a descriptor (only as much as fits into our buffer). I tested this patch on Suse, Redhat, and Darwin. [SVN r66650] --- src/engine/src/execunix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/engine/src/execunix.c b/src/engine/src/execunix.c index effd27138..ef9dba003 100644 --- a/src/engine/src/execunix.c +++ b/src/engine/src/execunix.c @@ -258,6 +258,10 @@ void exec_cmd close( out[1] ); close( err[1] ); + /* set both file descriptors to non-blocking */ + fcntl(out[0], F_SETFL, O_NONBLOCK); + fcntl(err[0], F_SETFL, O_NONBLOCK); + /* child writes stdout to out[1], parent reads from out[0] */ cmdtab[ slot ].fd[ OUT ] = out[0]; cmdtab[ slot ].stream[ OUT ] = fdopen( cmdtab[ slot ].fd[ OUT ], "rb" );