turn script/web_concurrency into a bash script, heroku did not like the ruby script

This commit is contained in:
Konstantin Haase 2015-10-09 09:13:46 +02:00
parent 0890d0b76a
commit 815d9e6e9b

View File

@ -1,33 +1,20 @@
#!/usr/bin/env ruby --disable=gems --disable=rubyopt #!/bin/bash
GC.disable
module System if [[ "$RACK_ENV" == "development" ]]; then
extend self echo -n 2
def cpu_count exit 0
return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java fi
return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist? '/proc/cpuinfo'
require 'win32ole'
WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
rescue LoadError
Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1
end
end
if ENV['DYNO'] case $(ulimit -u) in
# we're on Heroku 256) echo -n 2; exit 0;;
case `ulimit -u`.to_i 512) echo -n 4; exit 0;;
when 256 then concurrency = 2 # 1x dyno 32768)
when 512 then concurrency = 4 # 2x dyno if [[ "$1" == "--nginx" ]]; then
when 32768 then concurrency = 16 # px dyno echo -n 4
else $stderr.puts "Unkown dyno type, selecting concurrency of 4, because" else
end echo -n 16
end fi
exit 0;;
esac
case ENV['RACK_ENV'] || 'development' echo -n 4
when 'production' then concurrency ||= System.cpu_count
when 'development' then concurrency ||= 2 # use at least two so we can be sure things work concurrencly
else concurrency ||= 1
end
concurrency = System.cpu_count if ARGV[0] == '--nginx' and System.cpu_count < concurrency
print concurrency