Skip to content

Instantly share code, notes, and snippets.

@felixyz
Created June 15, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixyz/5788375 to your computer and use it in GitHub Desktop.
Save felixyz/5788375 to your computer and use it in GitHub Desktop.
MRI pipe limit (on OS X). This script fails on my Mac after creating 125 x 2 pipe endpoints, raising "Too many open files (Errno::EMFILE)" This is the cause of the problem illustrated here: https://gist.github.com/Felixyz/5788285
wakeups = []
wakers = []
puts "Creating pipes..."
200.times do |n|
puts "[#{n}]"
wakeup, waker = IO.pipe
wakeups << wakeup
wakers << waker
end
puts "Closing pipes..."
wakeups.each {|pipe| pipe.close rescue nil}
wakers.each {|pipe| pipe.close rescue nil}
@felixyz
Copy link
Author

felixyz commented Jun 15, 2013

Just in case anyone stumbles upon this: the problem is the OS limit on open files, as seen by running ulimit -a
Seems the default value has been increased btw 10.8.2 and 10.8.4. In any case, raising the number of allowed file descriptors solves the problem. (http://superuser.com/questions/261023/how-to-change-default-ulimit-values-in-mac-os-x-10-6)

@felixyz
Copy link
Author

felixyz commented Jun 15, 2013

Interesting to note that JRuby copes even with a small ulimit -n value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment