diff --git a/frameworks/Ruby/grape/config/auto_tune.rb b/frameworks/Ruby/grape/config/auto_tune.rb deleted file mode 100644 index aff6b73b997..00000000000 --- a/frameworks/Ruby/grape/config/auto_tune.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 64 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - raise "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - [(Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil, MIN_WORKERS].max - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $PROGRAM_NAME == __FILE__ diff --git a/frameworks/Ruby/grape/grape-iodine.dockerfile b/frameworks/Ruby/grape/grape-iodine.dockerfile index 4e20c95ba1c..e70eaff8e27 100644 --- a/frameworks/Ruby/grape/grape-iodine.dockerfile +++ b/frameworks/Ruby/grape/grape-iodine.dockerfile @@ -21,4 +21,4 @@ ENV MAX_THREADS=1 EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/padrino/config/auto_tune.rb b/frameworks/Ruby/padrino/config/auto_tune.rb deleted file mode 100644 index 54ae1e08731..00000000000 --- a/frameworks/Ruby/padrino/config/auto_tune.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 128 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - fail "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - (Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $0 == __FILE__ diff --git a/frameworks/Ruby/padrino/padrino.dockerfile b/frameworks/Ruby/padrino/padrino.dockerfile index 50cdbe55042..217822872bb 100644 --- a/frameworks/Ruby/padrino/padrino.dockerfile +++ b/frameworks/Ruby/padrino/padrino.dockerfile @@ -18,4 +18,4 @@ EXPOSE 8080 ENV RUBY_YJIT_ENABLE=1 ENV RACK_ENV=production -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/rack-app/config/auto_tune.rb b/frameworks/Ruby/rack-app/config/auto_tune.rb deleted file mode 100644 index 1e075f56911..00000000000 --- a/frameworks/Ruby/rack-app/config/auto_tune.rb +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 64 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - raise "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - [(Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil, MIN_WORKERS].max - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $PROGRAM_NAME == __FILE__ diff --git a/frameworks/Ruby/rack-app/config/puma.rb b/frameworks/Ruby/rack-app/config/puma.rb deleted file mode 100644 index 1b6d05d8ac0..00000000000 --- a/frameworks/Ruby/rack-app/config/puma.rb +++ /dev/null @@ -1,10 +0,0 @@ -require_relative 'auto_tune' - -# FWBM only... use the puma_auto_tune gem in production! -_num_workers, num_threads = auto_tune - -threads num_threads - -before_fork do - Sequel::DATABASES.each(&:disconnect) -end diff --git a/frameworks/Ruby/rack-app/rack-app.dockerfile b/frameworks/Ruby/rack-app/rack-app.dockerfile index 759d1eb8629..9fc9af1cef3 100644 --- a/frameworks/Ruby/rack-app/rack-app.dockerfile +++ b/frameworks/Ruby/rack-app/rack-app.dockerfile @@ -18,4 +18,4 @@ COPY . . EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/rack-sequel/config/auto_tune.rb b/frameworks/Ruby/rack-sequel/config/auto_tune.rb deleted file mode 100644 index 495956c0700..00000000000 --- a/frameworks/Ruby/rack-sequel/config/auto_tune.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 64 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - fail "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - (Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $0 == __FILE__ diff --git a/frameworks/Ruby/rack/rack-iodine.dockerfile b/frameworks/Ruby/rack/rack-iodine.dockerfile index 26f65700e15..73567286769 100644 --- a/frameworks/Ruby/rack/rack-iodine.dockerfile +++ b/frameworks/Ruby/rack/rack-iodine.dockerfile @@ -19,4 +19,4 @@ COPY . . EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/rails/rails-iodine.dockerfile b/frameworks/Ruby/rails/rails-iodine.dockerfile index 90020e652fa..615ed9dfdd6 100644 --- a/frameworks/Ruby/rails/rails-iodine.dockerfile +++ b/frameworks/Ruby/rails/rails-iodine.dockerfile @@ -24,4 +24,4 @@ ENV RAILS_ENV=production_postgresql ENV PORT=8080 ENV REDIS_URL=redis://localhost:6379/0 CMD service redis-server start && \ - bundle exec iodine -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) + bundle exec iodine -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/roda-sequel/config/auto_tune.rb b/frameworks/Ruby/roda-sequel/config/auto_tune.rb deleted file mode 100644 index 495956c0700..00000000000 --- a/frameworks/Ruby/roda-sequel/config/auto_tune.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 64 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - fail "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - (Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $0 == __FILE__ diff --git a/frameworks/Ruby/roda-sequel/roda-sequel-postgres-iodine-mri.dockerfile b/frameworks/Ruby/roda-sequel/roda-sequel-postgres-iodine-mri.dockerfile index db7fbc995f1..1bcf1d0866f 100644 --- a/frameworks/Ruby/roda-sequel/roda-sequel-postgres-iodine-mri.dockerfile +++ b/frameworks/Ruby/roda-sequel/roda-sequel-postgres-iodine-mri.dockerfile @@ -19,4 +19,4 @@ ENV DBTYPE=postgresql EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/sinatra-sequel/config/auto_tune.rb b/frameworks/Ruby/sinatra-sequel/config/auto_tune.rb deleted file mode 100644 index 495956c0700..00000000000 --- a/frameworks/Ruby/sinatra-sequel/config/auto_tune.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 64 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - fail "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - (Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $0 == __FILE__ diff --git a/frameworks/Ruby/sinatra-sequel/sinatra-sequel-iodine.dockerfile b/frameworks/Ruby/sinatra-sequel/sinatra-sequel-iodine.dockerfile index 7684f3ca869..870e2ef2e65 100644 --- a/frameworks/Ruby/sinatra-sequel/sinatra-sequel-iodine.dockerfile +++ b/frameworks/Ruby/sinatra-sequel/sinatra-sequel-iodine.dockerfile @@ -18,4 +18,4 @@ ENV DBTYPE=mysql EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/sinatra-sequel/sinatra-sequel-postgres-iodine-mri.dockerfile b/frameworks/Ruby/sinatra-sequel/sinatra-sequel-postgres-iodine-mri.dockerfile index 98e42167f64..fa0db65af57 100644 --- a/frameworks/Ruby/sinatra-sequel/sinatra-sequel-postgres-iodine-mri.dockerfile +++ b/frameworks/Ruby/sinatra-sequel/sinatra-sequel-postgres-iodine-mri.dockerfile @@ -18,4 +18,4 @@ ENV DBTYPE=postgresql EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/sinatra/config/auto_tune.rb b/frameworks/Ruby/sinatra/config/auto_tune.rb deleted file mode 100644 index 81bdabf7619..00000000000 --- a/frameworks/Ruby/sinatra/config/auto_tune.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env ruby -# Instantiate about one process per X MiB of available memory, scaling up to as -# close to MAX_THREADS as possible while observing an upper bound based on the -# number of virtual/logical CPUs. If there are fewer processes than -# MAX_THREADS, add threads per process to reach MAX_THREADS. -require 'etc' - -KB_PER_WORKER = 96 * 1_024 # average of peak PSS of single-threaded processes (watch smem -k) -MIN_WORKERS = 2 -MAX_WORKERS_PER_VCPU = 1.25 # virtual/logical -MIN_THREADS_PER_WORKER = 1 -MAX_THREADS = Integer(ENV['MAX_CONCURRENCY'] || 256) - -def meminfo(arg) - File.open('/proc/meminfo') do |f| - f.each_line do |line| - key, value = line.split(/:\s+/) - return value.split(/\s+/).first.to_i if key == arg - end - end - - fail "Unable to find `#{arg}' in /proc/meminfo!" -end - -def auto_tune - avail_mem = meminfo('MemAvailable') * 0.8 - MAX_THREADS * 1_024 - - workers = [ - [(1.0 * avail_mem / KB_PER_WORKER).floor, MIN_WORKERS].max, - (Etc.nprocessors * MAX_WORKERS_PER_VCPU).ceil - ].min - - threads_per_worker = [ - workers < MAX_THREADS ? (1.0 * MAX_THREADS / workers).ceil : -Float::INFINITY, - MIN_THREADS_PER_WORKER - ].max - - [workers, threads_per_worker] -end - -p auto_tune if $0 == __FILE__ diff --git a/frameworks/Ruby/sinatra/sinatra-iodine.dockerfile b/frameworks/Ruby/sinatra/sinatra-iodine.dockerfile index 171a0745457..921005ab3b1 100644 --- a/frameworks/Ruby/sinatra/sinatra-iodine.dockerfile +++ b/frameworks/Ruby/sinatra/sinatra-iodine.dockerfile @@ -18,4 +18,4 @@ ENV DBTYPE=mysql EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4)) diff --git a/frameworks/Ruby/sinatra/sinatra-postgres-iodine-mri.dockerfile b/frameworks/Ruby/sinatra/sinatra-postgres-iodine-mri.dockerfile index 7dbd84dfeca..7cb23cc9211 100644 --- a/frameworks/Ruby/sinatra/sinatra-postgres-iodine-mri.dockerfile +++ b/frameworks/Ruby/sinatra/sinatra-postgres-iodine-mri.dockerfile @@ -18,4 +18,4 @@ ENV DBTYPE=postgresql EXPOSE 8080 -CMD bundle exec iodine -p 8080 -w $(ruby config/auto_tune.rb | grep -Eo '[0-9]+' | head -n 1) +CMD bundle exec iodine -p 8080 -w $(($(nproc)*5/4))