40 lines
1.4 KiB
INI
40 lines
1.4 KiB
INI
def get_max_memory()
|
|
return ENV['MEMORY_LIMIT_IN_BYTES'].to_i if ENV.has_key? 'MEMORY_LIMIT_IN_BYTES'
|
|
|
|
# Assume unlimited memory. 0.size is the number of bytes a Ruby
|
|
# Fixnum class can hold. One bit is used for sign and one is used
|
|
# by Ruby to determine whether it's a number or pointer to an object.
|
|
# That's why we subtract two bits. This expresion should therefore be
|
|
# the largest signed Fixnum possible.
|
|
(2 ** (8*0.size - 2) - 1)
|
|
end
|
|
|
|
def get_min_threads()
|
|
ENV.fetch('PUMA_MIN_THREADS', '0').to_i
|
|
end
|
|
|
|
def get_max_threads()
|
|
ENV.fetch('PUMA_MAX_THREADS', '16').to_i
|
|
end
|
|
|
|
# Determine the maximum number of workers that are allowed by the available
|
|
# memory. Puma documentation recommends the maximum number of workers to be
|
|
# set to the number cores.
|
|
def get_workers()
|
|
return ENV['PUMA_WORKERS'].to_i if ENV.has_key? 'PUMA_WORKERS'
|
|
|
|
base_memory = 50 * 1024 * 1024
|
|
per_worker_base_memory = 15 * 1024 * 1024
|
|
per_thread_memory = 128 * 1024
|
|
|
|
cores = ENV.fetch('NUMBER_OF_CORES', '1').to_i
|
|
per_worker_memory = per_worker_base_memory + per_thread_memory*get_max_threads()
|
|
max_workers = (get_max_memory() - base_memory) / per_worker_memory
|
|
|
|
[cores, max_workers].min
|
|
end
|
|
|
|
environment ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
|
|
threads get_min_threads(), get_max_threads()
|
|
workers get_workers()
|
|
bind 'tcp://0.0.0.0:8080'
|