Skip to content

Instantly share code, notes, and snippets.

@bookmebus
Created November 25, 2018 03:15
Show Gist options
  • Save bookmebus/e5f81fec0a1ba7128b79ce65e98032e5 to your computer and use it in GitHub Desktop.
Save bookmebus/e5f81fec0a1ba7128b79ce65e98032e5 to your computer and use it in GitHub Desktop.
ElasticBeanStalk custom puma config for multiprocess x workers.
container_commands:
# directory '/var/app/current'
# threads 8, 32
# workers %x(grep -c processor /proc/cpuinfo)
# bind 'unix:///var/run/puma/my_app.sock'
# pidfile '/var/run/puma/puma.pid'
# stdout_redirect '/var/log/puma/puma.log', '/var/log/puma/puma.log', true
# daemonize false
01backup_config:
command: "cp -n /opt/elasticbeanstalk/support/conf/pumaconf.rb /opt/elasticbeanstalk/support/conf/pumaconf.rb.original"
02_edit_comment_default_threads_config:
# threads 8, 32 -> threads 4, 8
command: "sed -i 's/threads 8, 32/threads 4, 8/' /opt/elasticbeanstalk/support/conf/pumaconf.rb"
03_delete_default_worker_config:
# workers %x(grep -c processor /proc/cpuinfo) -> workers 5 * %x( grep -c processor /proc/cpuinfo ).to_i
command: "sed -i '/workers/d' /opt/elasticbeanstalk/support/conf/pumaconf.rb"
04_insert_new_worker_after_threads_config:
command: "sed -i '/threads/a workers 5 * %x( grep -c processor /proc/cpuinfo ).to_i' /opt/elasticbeanstalk/support/conf/pumaconf.rb"
@bookmebus
Copy link
Author

bookmebus commented Nov 25, 2018

Elasticbeanstalk puma default configuration which resides in /opt/elasticbeanstalk/support/conf/pumaconf.rb

directory '/var/app/current'
threads 8, 32
workers %x(grep -c processor /proc/cpuinfo)
bind 'unix:///var/run/puma/my_app.sock'
pidfile '/var/run/puma/puma.pid'
stdout_redirect '/var/log/puma/puma.log', '/var/log/puma/puma.log', true
daemonize false

The number of workers is set to equal to the number cpu cores. If the instance RAM is big this config does not seem good enough especially for Large instance type with MRI Ruby. As suggested from puma docs:

Rules of thumb In MRI:

  • Use cluster mode and set the number of workers to 1.5x the number of CPU cores in machine, minimum 2.
  • Set the number of threads to desired concurrent requests / number of workers. Puma defaults to 16 that is a decent number.

number_of_threads = wanted_number_of_concurrency/number_of_workers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment