From: Brent Roman Date: 2009-01-14T15:23:16+09:00 Subject: [ruby-core:21332] Re: [PATCH] drastically improve rb_waitpid for short-lived children Evan, Here's a quick Ruby-only hack demonstrating a drastically improved waitpid for short-lived children without resorting to any sort of polling. Here's the output on my 1.6Ghz mac mini running Ubuntu 7.10: ## ... ###6.393058 ## ... ###0.42344 That's a 15x speedup. Doing this right probably requires a 'C' patch to the core along these lines. We'd need a handler for SIGCHLD and probably a hash that maps pids to waiting threads. Looks promising... --------------- # quick demo of the speed up possible by trapping SIGCHLD # instead of waiting for Ruby's internal rbthreadpoll() # A proof up concept for a possible patch n = 100 def nullShell pid = fastShell Process.waitall end def fastShell fork { exec "echo", "-n", "#" } end def time start = Time.now yield Time.now - start end Thread.new { t=Thread.current puts time{n.times{nullShell}} Signal.trap("CHLD") { t.wakeup #Ruby traps run on the Thread.main } puts time{n.times{nullShell}} }.join -- View this message in context: http://www.nabble.com/-ruby-core%3A21302---PATCH--drastically-improve-rb_waitpid-for-short-lived-children-tp21431928p21450668.html Sent from the ruby-core mailing list archive at Nabble.com.