diff options
author | Eric Wong <e@80x24.org> | 2018-08-20 20:56:52 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2018-08-20 21:09:42 +0000 |
commit | 0ed746e9b9f03a5067aa97cc4ed54b9e42443727 (patch) | |
tree | ea9d4ae65457ce57902208295e22d8d61bad0e88 /lib/unicorn.rb | |
parent | d03dd4e9e4ff29689752b7c82202008fefaf1210 (diff) | |
download | unicorn-0ed746e9b9f03a5067aa97cc4ed54b9e42443727.tar.gz |
We have never had any need for pipes with the default 64K capacity on Linux. Our pipes are only used for tiny writes in signal handlers and to perform parent shutdown detection. With the current /proc/sys/fs/pipe-user-pages-soft default, only 1024 pipes can be created by an unprivileged user before Linux clamps down the pipe size to 4K (a single page) for newly-created pipes[1]. So avoid penalizing OTHER pipe users who could benefit from the increased capacity and use only a single page for ourselves. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/pipe.c?h=v4.18#n642
Diffstat (limited to 'lib/unicorn.rb')
-rw-r--r-- | lib/unicorn.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 85e4df1..b6dae36 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -2,6 +2,7 @@ require 'etc' require 'stringio' require 'kgio' +require 'raindrops' require 'io/wait' begin @@ -113,9 +114,22 @@ module Unicorn exc.backtrace.each { |line| logger.error(line) } end - # remove this when we only support Ruby >= 2.0 + F_SETPIPE_SZ = 1031 if RUBY_PLATFORM =~ /linux/ + def self.pipe # :nodoc: - Kgio::Pipe.new.each { |io| io.close_on_exec = true } + Kgio::Pipe.new.each do |io| + io.close_on_exec = true # remove this when we only support Ruby >= 2.0 + + # shrink pipes to minimize impact on /proc/sys/fs/pipe-user-pages-soft + # limits. + if defined?(F_SETPIPE_SZ) + begin + io.fcntl(F_SETPIPE_SZ, Raindrops::PAGE_SIZE) + rescue Errno::EINVAL + # old kernel + end + end + end end # :startdoc: end |