Merge branch 'unicorn-worker-memory-limit' into 'master'

Try to leave 1GB RAM free of Unicorn workers

If we keep adding Unicorn workers as CPU cores go up we can run out of
memory. After this change:
- the minimum number of Unicorn worker processes is 2
- if there is enough RAM, we get ncores+1 worker processes
- assuming 250MB/Unicorn, leave 1GB RAM free for other services. (1.5GB
  RAM: max 2 Unicorns, 2GB: max 4 Unicorns, 4GB: max 12 Unicorns, etc.)

See merge request !395
This commit is contained in:
Marin Jankovski 2015-06-29 13:15:47 +00:00
commit 2f623a5e9b
1 changed files with 10 additions and 1 deletions

View File

@ -185,7 +185,16 @@ default['gitlab']['gitlab-rails']['initial_root_password'] = nil
default['gitlab']['unicorn']['enable'] = true
default['gitlab']['unicorn']['ha'] = false
default['gitlab']['unicorn']['log_directory'] = "/var/log/gitlab/unicorn"
default['gitlab']['unicorn']['worker_processes'] = node['cpu']['total'].to_i + 1
default['gitlab']['unicorn']['worker_processes'] = [
2, # Two is the minimum or HTTP(S) Git pushes will no longer work.
[
# Cores + 1 gives good CPU utilization.
node['cpu']['total'].to_i + 1,
# See how many 250MB worker processes fit in (total RAM - 1GB). We add
# 128000 KB in the numerator to get rounding instead of integer truncation.
(node['memory']['total'].to_i - 1048576 + 128000) / 256000
].min # min because we want to exceed neither CPU nor RAM
].max # max because we need at least 2 workers
default['gitlab']['unicorn']['listen'] = '127.0.0.1'
default['gitlab']['unicorn']['port'] = 8080
default['gitlab']['unicorn']['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'