David, On Wed, Apr 21, 2010 at 20:15, David Schlosnagle <schlo...@gmail.com> wrote: > On Wed, Apr 21, 2010 at 9:14 PM, Martin Buchholz <marti...@google.com> wrote:
> Running ManyProcesses with Apple's version of 1.6.0_17-b04-248, > averages around 45 seconds and 4010 started threads. > Running ManyProcesses with the bsd-port of OpenJDK7 on OS X without > these changes, averages around 16 seconds and 4010 started threads. > Running ManyProcesses with the bsd-port of OpenJDK7 on OS X with these > changes, averages around 14 seconds and around 14 started threads. > > One definite benefit is that the total number of started threads drops > from 4010 to around 14. Compared to the Apple version of Java 6, I see > the multiple factor speedup of 3x. The speedup on my machine for > OpenJDK7 bsd-port with this patch versus without is much smaller, of > course that could be due differences in OS and hardware (I'm running > on an older Intel Core 2 Duo). I did some more benchmarking myself and can confirm that the win is less compared to stock openjdk7. It is all highly dependent on how often GC is run to reclaim file descriptors, and how much the performance of fork+exec is dependent on the number of unreclaimed file descriptors. >> Yes, the streams really should be final, >> but it's not worth the boilerplate handsprings to make them so. > > I'm not sure I quite follow, I was thinking something along the lines of: > > private final OutputStream stdin; > private final InputStream stdout; > private final InputStream stderr; > > // ...snip... > > UNIXProcess(final byte[] prog, > final byte[] argBlock, final int argc, > final byte[] envBlock, final int envc, > final byte[] dir, > final int[] fds, > final boolean redirectErrorStream) > throws IOException { > > pid = forkAndExec(prog, > argBlock, argc, > envBlock, envc, > dir, > fds, > redirectErrorStream); > > stdin = (fds[0] == -1) ? > ProcessBuilder.NullOutputStream.INSTANCE : > new ProcessPipeOutputStream(fds[0]); the creation of the file streams needs to be within a privileged block, else you might get a SecurityException. Martin