From 1250c867a78cda8c628cceb5a255376479d4a9f6 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 3 Dec 2022 15:46:10 +0000 Subject: [PATCH 1/1] Add a library routine to get the CPU core count --- cookbooks/chef/libraries/cpu.rb | 11 +++++++++++ .../community/templates/default/web_only.yml.erb | 2 +- cookbooks/stateofthemap/recipes/jekyll.rb | 2 +- cookbooks/tile/templates/default/render-lowzoom.erb | 4 ++-- cookbooks/tile/templates/default/renderd.conf.erb | 2 +- cookbooks/tile/templates/default/update-lowzoom.erb | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 cookbooks/chef/libraries/cpu.rb diff --git a/cookbooks/chef/libraries/cpu.rb b/cookbooks/chef/libraries/cpu.rb new file mode 100644 index 000000000..a7992a4ca --- /dev/null +++ b/cookbooks/chef/libraries/cpu.rb @@ -0,0 +1,11 @@ +module OpenStreetMap + module Mixin + module CPU + def cpu_cores + [self.dig("cpu", "total").to_i, self.dig("cpu", "cores").to_i, 4].max + end + end + end +end + +Chef::Node.include(OpenStreetMap::Mixin::CPU) diff --git a/cookbooks/community/templates/default/web_only.yml.erb b/cookbooks/community/templates/default/web_only.yml.erb index f3f58bb6e..4407553c9 100644 --- a/cookbooks/community/templates/default/web_only.yml.erb +++ b/cookbooks/community/templates/default/web_only.yml.erb @@ -32,7 +32,7 @@ env: ## How many concurrent web requests are supported? Depends on memory and CPU cores. ## will be set automatically by bootstrap based on detected CPUs, or you can override - UNICORN_WORKERS: <%= [2, node.dig('cpu', 'total').to_i, node.dig('cpu', 'cores').to_i].max %> + UNICORN_WORKERS: <%= node.cpu_cores %> ## TODO: The domain name this Discourse instance will respond to DISCOURSE_HOSTNAME: community.openstreetmap.org diff --git a/cookbooks/stateofthemap/recipes/jekyll.rb b/cookbooks/stateofthemap/recipes/jekyll.rb index fa2545e5f..a57d230b6 100644 --- a/cookbooks/stateofthemap/recipes/jekyll.rb +++ b/cookbooks/stateofthemap/recipes/jekyll.rb @@ -58,7 +58,7 @@ apache_module "rewrite" bundle_install "/srv/#{year}.stateofthemap.org" do action :nothing - options "--deployment --jobs #{[4, node.dig('cpu', 'total').to_i, node.dig('cpu', 'cores').to_i].max}" + options "--deployment --jobs #{node.cpu_cores}" user "root" group "root" notifies :run, "bundle_exec[/srv/#{year}.stateofthemap.org]" diff --git a/cookbooks/tile/templates/default/render-lowzoom.erb b/cookbooks/tile/templates/default/render-lowzoom.erb index 779730d1e..834eecc30 100644 --- a/cookbooks/tile/templates/default/render-lowzoom.erb +++ b/cookbooks/tile/templates/default/render-lowzoom.erb @@ -16,9 +16,9 @@ function update_<%= style %> --timestamp=${timestamp} \ --tile-dir=/srv/tile.openstreetmap.org/tiles \ --socket=/var/run/renderd/renderd.sock \ - --num-threads=<%= [4, node.dig('cpu', 'total').to_i - 1, node.dig('cpu', 'cores').to_i - 1].max %> \ + --num-threads=<%= node.cpu_cores - 1 %> \ --map="<%= style %>" \ - --max-load=<%= [4, node.dig('cpu', 'total').to_i, node.dig('cpu', 'cores').to_i].max %> \ + --max-load=<%= node.cpu_cores - 1 %> \ --min-zoom=0 --max-zoom=12 } diff --git a/cookbooks/tile/templates/default/renderd.conf.erb b/cookbooks/tile/templates/default/renderd.conf.erb index 60206d1ce..d29c58aa7 100644 --- a/cookbooks/tile/templates/default/renderd.conf.erb +++ b/cookbooks/tile/templates/default/renderd.conf.erb @@ -2,7 +2,7 @@ [renderd] socketname=/var/run/renderd/renderd.sock -num_threads=<%= [4, node.dig('cpu', 'total').to_i - 1, node.dig('cpu', 'cores').to_i - 1].max %> +num_threads=<%= node.cpu_cores - 1 %> tile_dir=/srv/tile.openstreetmap.org/tiles stats_file=/var/run/renderd/renderd.stats diff --git a/cookbooks/tile/templates/default/update-lowzoom.erb b/cookbooks/tile/templates/default/update-lowzoom.erb index 4f2821dba..81e138076 100644 --- a/cookbooks/tile/templates/default/update-lowzoom.erb +++ b/cookbooks/tile/templates/default/update-lowzoom.erb @@ -12,9 +12,9 @@ function update_tiles --timestamp=$(stat -c %Y "/srv/tile.openstreetmap.org/styles/<%= @style %>/project.xml") \ --tile-dir=/srv/tile.openstreetmap.org/tiles \ --socket=/var/run/renderd/renderd.sock \ - --num-threads=<%= [4, node.dig('cpu', 'total').to_i - 1, node.dig('cpu', 'cores').to_i - 1].max %> \ + --num-threads=<%= node.cpu_cores - 1 %> \ --map="<%= @style %>" \ - --max-load=<%= [4, node.dig('cpu', 'total').to_i, node.dig('cpu', 'cores').to_i].max %> \ + --max-load=<%= node.cpu_cores - 1 %> \ --min-zoom=0 --max-zoom=12 } -- 2.39.5