-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POSIX::Spawn. slower than Kernel.
on MRI 2.2
#70
Comments
I tried to run the above benchmark script from
Looks like posix-spawn performs significantly better when the parent process is memory huge e.g., rails worker. |
Thank you @felixbuenemann for starting this discussion and providing your methodology and results. I think the raw nanosecond overhead doesn't detract from the value of posix-spawn from any use case I can think of. @mintuhouse's benchmark is a great example, and here's another take on an extremely simplistic "more realistic" benchmark, this time running a process that isn't a pure NOOP like require "benchmark"
require "posix/spawn"
n = 500
cmd = "sleep .01"
Benchmark.bm do |x|
GC.start
x.report("Kernel.\`") { n.times { Kernel.` cmd } }
GC.start
x.report("POSIX::Spawn.\`") { n.times { POSIX::Spawn.` cmd } }
end
|
I actually tried to make a version of @felixbuenemann benchmark which had a parent process with a lot of memory n = 10_000
cmd = "/bin/echo".freeze
string = ""
1_000_000_00.times{ string << "hello"} But no matter how big I made it I couldn't get posix-spawn to be faster. posix spawn was always 2x the time. Then I made this benchmark to test memory used because of forking. require "benchmark"
require "posix/spawn"
n = 10_000
cmd = "free -m"
string = ""
1_000_000_00.times{ string << "hello"}
puts "Sleeping for 10 seconds. Please run free -m directly in another shell"
sleep 10
GC.start
puts "Kernel.\`"
puts Kernel.` cmd
GC.start
puts "POSIX::Spawn.\`"
puts POSIX::Spawn.` cmd
So this either means that copy-on-write is really doing its job and creating zero memory overhead, or the ruby backtick implementation changed at some point.
|
I noticed that posix-spawn's implementation of the back-tick operator is significantly slower than the built-in implementation of MRI ruby 2.2.2 on both Linux and Mac OS X:
Result on Mac OS X 10.11 Beta 6, Darwin 15.0.0 x86_64, ruby 2.2.2p133, posix-spawn 0.3.11:
Result on Ubuntu Server 14.04.3 LTS, Linux 3.13.0 x86_64, ruby 2.2.2p95, posix-spawn 0.3.11:
The text was updated successfully, but these errors were encountered: