From eb798800c7395e14d3e687b28a2669e4eb9e0cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 26 Mar 2020 14:13:23 +0100 Subject: [PATCH] set memory and cpu limits on the container MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- defaults/main.yml | 6 ++++++ tasks/container.yml | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/defaults/main.yml b/defaults/main.yml index 160eaae..e947924 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,6 +19,12 @@ beacon_node_metrics_port: 9200 # rpc / administrative beacon_node_rpc_port: 9900 +# resource limits, mem in MB +beacon_node_cpu_limit: 0.60 +beacon_node_mem_limit: '{{ (ansible_memtotal_mb * 0.6) | int }}' +beacon_node_cpu_reserve: 0.20 +beacon_node_mem_reserve: '{{ (ansible_memtotal_mb * 0.2) | int }}' + # general container management compose_state: 'present' compose_recreate: 'smart' diff --git a/tasks/container.yml b/tasks/container.yml index 3b0be98..eac320e 100644 --- a/tasks/container.yml +++ b/tasks/container.yml @@ -15,6 +15,14 @@ container_name: '{{ beacon_node_cont_name }}' image: '{{ beacon_node_cont_image }}' restart: 'always' + deploy: + resources: + limits: + cpus: '{{ beacon_node_cpu_limit | string }}' + memory: '{{ beacon_node_mem_limit }}M' + reservations: + cpus: '{{ beacon_node_cpu_reserve | string }}' + memory: '{{ beacon_node_mem_reserve }}M' ports: - '127.0.0.1:{{ beacon_node_rpc_port }}:{{ beacon_node_rpc_port }}/tcp' - '{{ beacon_node_metrics_port }}:{{ beacon_node_metrics_port }}/tcp'