travis-api/script/web_concurrency

34 lines
1.1 KiB
Ruby
Executable File

#!/usr/bin/env ruby --disable=gems --disable=rubyopt
GC.disable
module System
extend self
def cpu_count
return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java
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']
# we're on Heroku
case `uname -u`.to_i
when 256 then concurrency = 2 # 1x dyno
when 512 then concurrency = 4 # 2x dyno
when 32768 then concurrency = 16 # px dyno
else $stderr.puts "Unkown dyno type, selecting concurrency of 4, because"
end
end
case ENV['RACK_ENV'] || 'development'
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