Permalink
Browse files

Add hooks to use posix-spawn gem if available.

  • Loading branch information...
1 parent 4eb18d2 commit aa36e450615a5ebbc27fa4961ad0e970233177f4 Brian Durand committed Feb 29, 2012
Showing with 12 additions and 0 deletions.
  1. +3 −0 README.md
  2. +9 −0 lib/cocaine/command_line.rb
View
3 README.md
@@ -119,6 +119,9 @@ But you don't have to, as you saw above where it doesn't use this. But you CAN l
Cocaine::CommandLine.logger = Logger.new(STDOUT)
Cocaine::CommandLine.new("date").run # => Logs this -> Command :: date
```
+## POSIX Spawn
+
+You can potentially increase performance by installing the posix-spawn gem (https://rubygems.org/gems/posix-spawn). This gem can keep your application's heap from being copied when forking command line processesG. For applications with large heaps the gain can be significant. To include posix-spawn, simply add it to your Gemfile or, if you don't use bundler, install the gem.
## License
View
9 lib/cocaine/command_line.rb
@@ -1,5 +1,14 @@
module Cocaine
class CommandLine
+ # Check for posix-spawn gem. If it is available it will prevent the invoked processes
+ # from getting a copy of the ruby heap which can lead to significant performance gains.
+ begin
+ require 'posix/spawn'
+ extend POSIX::Spawn
+ rescue LoadError => e
+ # posix-spawn gem not available
+ end
+
class << self
attr_accessor :path, :logger
end

0 comments on commit aa36e45

Please sign in to comment.