Skip to content

Commit 524c3b3

Browse files
committed
Configure GOMAXPROCS and GOMEMLIMIT based on requests cpu and memory
Signed-off-by: Friedrich Gonzalez <[email protected]>
1 parent c35087e commit 524c3b3

10 files changed

+74
-24
lines changed

cortex/alertmanager.libsonnet

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
local volumeMount = $.core.v1.volumeMount,
44
local volume = $.core.v1.volume,
55
local container = $.core.v1.container,
6+
local envType = container.envType,
67
local statefulSet = $.apps.v1.statefulSet,
78
local service = $.core.v1.service,
89
local configMap = $.core.v1.configMap,
@@ -98,6 +99,12 @@
9899
container.withPorts($.util.defaultPorts + mode.ports) +
99100
container.withEnvMap($.alertmanager_env_map) +
100101
container.withEnvMixin([container.envType.fromFieldPath('POD_IP', 'status.podIP')]) +
102+
container.withEnvMixin([
103+
envType.withName('GOMAXPROCS') +
104+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
105+
envType.withName('GOMEMLIMIT') +
106+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
107+
]) +
101108
container.withArgsMixin(
102109
$.util.mapToFlags($.alertmanager_args) +
103110
mode.flags
@@ -108,14 +115,12 @@
108115
[volumeMount.new('alertmanager-fallback-config', '/configs')]
109116
else []
110117
) +
111-
$.util.resourcesRequests('100m', '1Gi') +
118+
$.util.resourcesRequests('1', '1Gi') +
112119
$.util.readinessProbe +
113120
$.jaeger_mixin
114121
else {},
115122

116123
alertmanager_env_map:: {
117-
GOMAXPROCS: '1',
118-
GOMEMLIMIT: '1GiB',
119124
},
120125

121126
alertmanager_statefulset:

cortex/compactor.libsonnet

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
local container = $.core.v1.container,
3+
local envType = container.envType,
34
local pvc = $.core.v1.persistentVolumeClaim,
45
local statefulSet = $.apps.v1.statefulSet,
56
local volumeMount = $.core.v1.volumeMount,
@@ -44,16 +45,20 @@
4445
container.withPorts($.compactor_ports) +
4546
container.withArgsMixin($.util.mapToFlags($.compactor_args)) +
4647
container.withEnvMap($.compactor_env_map) +
48+
container.withEnvMixin([
49+
envType.withName('GOMAXPROCS') +
50+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
51+
envType.withName('GOMEMLIMIT') +
52+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
53+
]) +
4754
container.withVolumeMountsMixin([volumeMount.new('compactor-data', '/data')]) +
4855
// Do not limit compactor CPU and request enough cores to honor configured max concurrency.
49-
$.util.resourcesRequests($._config.cortex_compactor_max_concurrency, '6Gi') +
56+
$.util.resourcesRequests($._config.cortex_compactor_max_concurrency, '5Gi') +
5057
$.util.resourcesLimits(null, '6Gi') +
5158
$.util.readinessProbe +
5259
$.jaeger_mixin,
5360

5461
compactor_env_map:: {
55-
GOMAXPROCS: std.toString($._config.cortex_compactor_max_concurrency),
56-
GOMEMLIMIT: '5GiB',
5762
},
5863

5964
newCompactorStatefulSet(name, container)::

cortex/distributor.libsonnet

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
local container = $.core.v1.container,
3+
local envType = container.envType,
34
local containerPort = $.core.v1.containerPort,
45

56
distributor_args::
@@ -35,8 +36,6 @@
3536
},
3637

3738
distributor_env_map:: {
38-
GOMAXPROCS: '2',
39-
GOMEMLIMIT: '2GiB',
4039
},
4140

4241
distributor_ports:: $.util.defaultPorts,
@@ -45,6 +44,12 @@
4544
container.new('distributor', $._images.distributor) +
4645
container.withPorts($.distributor_ports) +
4746
container.withArgsMixin($.util.mapToFlags($.distributor_args)) +
47+
container.withEnvMixin([
48+
envType.withName('GOMAXPROCS') +
49+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
50+
envType.withName('GOMEMLIMIT') +
51+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
52+
]) +
4853
container.withEnvMap($.distributor_env_map) +
4954
$.util.resourcesRequests('2', '2Gi') +
5055
$.util.resourcesLimits(null, '4Gi') +

cortex/ingester.libsonnet

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@
4949

5050
local name = 'ingester',
5151
local container = $.core.v1.container,
52+
local envType = container.envType,
5253

5354
ingester_container::
5455
container.new(name, $._images.ingester) +
5556
container.withPorts($.ingester_ports) +
5657
container.withArgsMixin($.util.mapToFlags($.ingester_args)) +
5758
container.withEnvMap($.ingester_env_map) +
59+
container.withEnvMixin([
60+
envType.withName('GOMAXPROCS') +
61+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
62+
envType.withName('GOMEMLIMIT') +
63+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
64+
]) +
5865
$.util.resourcesRequests('4', '15Gi') +
5966
$.util.resourcesLimits(null, '25Gi') +
6067
$.util.readinessProbe +
@@ -63,8 +70,6 @@
6370
ingester_deployment_labels:: {},
6471

6572
ingester_env_map:: {
66-
GOMAXPROCS: '4',
67-
GOMEMLIMIT: '15GiB',
6873
},
6974

7075
local ingester_pvc =

cortex/querier.libsonnet

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
local container = $.core.v1.container,
3+
local envType = container.envType,
34

45
querier_args::
56
$._config.grpcConfig +
@@ -32,8 +33,6 @@
3233
querier_ports:: $.util.defaultPorts,
3334

3435
querier_env_map:: {
35-
GOMAXPROCS: '2',
36-
GOMEMLIMIT: '12GiB',
3736
JAEGER_REPORTER_MAX_QUEUE_SIZE: '1024', // Default is 100.
3837
},
3938

@@ -44,6 +43,12 @@
4443
$.jaeger_mixin +
4544
$.util.readinessProbe +
4645
container.withEnvMap($.querier_env_map) +
46+
container.withEnvMixin([
47+
envType.withName('GOMAXPROCS') +
48+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
49+
envType.withName('GOMEMLIMIT') +
50+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
51+
]) +
4752
$.util.resourcesRequests('2', '12Gi') +
4853
$.util.resourcesLimits(null, '24Gi'),
4954

cortex/query-frontend.libsonnet

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
local container = $.core.v1.container,
3+
local envType = container.envType,
34

45
query_frontend_args::
56
$._config.grpcConfig
@@ -43,14 +44,18 @@
4344
container.withPorts($.util.defaultPorts) +
4445
container.withArgsMixin($.util.mapToFlags($.query_frontend_args)) +
4546
container.withEnvMap($.query_frontend_env_map) +
47+
container.withEnvMixin([
48+
envType.withName('GOMAXPROCS') +
49+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
50+
envType.withName('GOMEMLIMIT') +
51+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
52+
]) +
4653
$.jaeger_mixin +
4754
$.util.readinessProbe +
4855
$.util.resourcesRequests('2', '600Mi') +
4956
$.util.resourcesLimits(null, '1200Mi'),
5057

5158
query_frontend_env_map:: {
52-
GOMAXPROCS: '2',
53-
GOMEMLIMIT: '600MiB',
5459
},
5560

5661
local deployment = $.apps.v1.deployment,

cortex/query-scheduler.libsonnet

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
local container = $.core.v1.container,
55
local deployment = $.apps.v1.deployment,
6+
local envType = container.envType,
67
local service = $.core.v1.service,
78

89
query_scheduler_args+::
@@ -18,6 +19,12 @@
1819
container.withPorts($.util.defaultPorts) +
1920
container.withArgsMixin($.util.mapToFlags($.query_scheduler_args)) +
2021
container.withEnvMap($.query_scheduler_env_map) +
22+
container.withEnvMixin([
23+
envType.withName('GOMAXPROCS') +
24+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
25+
envType.withName('GOMEMLIMIT') +
26+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
27+
]) +
2128
$.jaeger_mixin +
2229
$.util.readinessProbe +
2330
$.util.resourcesRequests('2', '1Gi') +
@@ -32,8 +39,6 @@
3239
deployment.mixin.spec.strategy.rollingUpdate.withMaxUnavailable(1),
3340

3441
query_scheduler_env_map:: {
35-
GOMAXPROCS: '2',
36-
GOMEMLIMIT: '1GiB',
3742
},
3843

3944
query_scheduler_deployment: if !$._config.query_scheduler_enabled then {} else

cortex/query-tee.libsonnet

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
local container = $.core.v1.container,
33
local containerPort = $.core.v1.containerPort,
44
local deployment = $.apps.v1.deployment,
5+
local envType = container.envType,
56
local service = $.core.v1.service,
67
local servicePort = $.core.v1.servicePort,
78

@@ -19,12 +20,16 @@
1920
]) +
2021
container.withArgsMixin($.util.mapToFlags($.query_tee_args)) +
2122
container.withEnvMap($.query_tee_env_map) +
23+
container.withEnvMixin([
24+
envType.withName('GOMAXPROCS') +
25+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
26+
envType.withName('GOMEMLIMIT') +
27+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
28+
]) +
2229
$.util.resourcesRequests('1', '512Mi') +
2330
$.jaeger_mixin,
2431

2532
query_tee_env_map:: {
26-
GOMAXPROCS: '1',
27-
GOMEMLIMIT: '512MiB',
2833
},
2934

3035
query_tee_deployment: if !($._config.query_tee_enabled) then {} else

cortex/ruler.libsonnet

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
local container = $.core.v1.container,
3+
local envType = container.envType,
34

45
ruler_args::
56
$._config.grpcConfig +
@@ -39,7 +40,13 @@
3940
container.withPorts($.util.defaultPorts) +
4041
container.withArgsMixin($.util.mapToFlags($.ruler_args)) +
4142
container.withEnvMap($.ruler_env_map) +
42-
$.util.resourcesRequests('1', '6Gi') +
43+
container.withEnvMixin([
44+
envType.withName('GOMAXPROCS') +
45+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
46+
envType.withName('GOMEMLIMIT') +
47+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
48+
]) +
49+
$.util.resourcesRequests('2', '6Gi') +
4350
$.util.resourcesLimits('16', '16Gi') +
4451
$.util.readinessProbe +
4552
$.jaeger_mixin
@@ -58,8 +65,6 @@
5865
else {},
5966

6067
ruler_env_map:: {
61-
GOMAXPROCS: '2',
62-
GOMEMLIMIT: '6GiB',
6368
},
6469

6570
local service = $.core.v1.service,

cortex/store-gateway.libsonnet

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
local container = $.core.v1.container,
3+
local envType = container.envType,
34
local podDisruptionBudget = $.policy.v1.podDisruptionBudget,
45
local pvc = $.core.v1.persistentVolumeClaim,
56
local statefulSet = $.apps.v1.statefulSet,
@@ -41,15 +42,19 @@
4142
container.withPorts($.store_gateway_ports) +
4243
container.withArgsMixin($.util.mapToFlags($.store_gateway_args)) +
4344
container.withEnvMap($.store_gateway_env_map) +
45+
container.withEnvMixin([
46+
envType.withName('GOMAXPROCS') +
47+
envType.valueFrom.resourceFieldRef.withResource('requests.cpu'),
48+
envType.withName('GOMEMLIMIT') +
49+
envType.valueFrom.resourceFieldRef.withResource('requests.memory'),
50+
]) +
4451
container.withVolumeMountsMixin([volumeMount.new('store-gateway-data', '/data')]) +
45-
$.util.resourcesRequests('1', '12Gi') +
52+
$.util.resourcesRequests('2', '12Gi') +
4653
$.util.resourcesLimits(null, '18Gi') +
4754
$.util.readinessProbe +
4855
$.jaeger_mixin,
4956

5057
store_gateway_env_map:: {
51-
GOMAXPROCS: '2',
52-
GOMEMLIMIT: '12GiB',
5358
},
5459

5560
newStoreGatewayStatefulSet(name, container)::

0 commit comments

Comments
 (0)