Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(default-memory-limits): set default memory limits #4960

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1alpha1/envoyproxy_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func DefaultShutdownManagerContainerResourceRequirements() *corev1.ResourceRequi
corev1.ResourceCPU: resource.MustParse(DefaultShutdownManagerCPUResourceRequests),
corev1.ResourceMemory: resource.MustParse(DefaultShutdownManagerMemoryResourceRequests),
},
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(DefaultShutdownManagerMemoryResourceLimits),
},
}
}

Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/kubernetes_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func DefaultResourceRequirements() *corev1.ResourceRequirements {
corev1.ResourceCPU: resource.MustParse(DefaultDeploymentCPUResourceRequests),
corev1.ResourceMemory: resource.MustParse(DefaultDeploymentMemoryResourceRequests),
},
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(DefaultDeploymentMemoryResourceLimits),
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ const (
DefaultDeploymentCPUResourceRequests = "100m"
// DefaultDeploymentMemoryResourceRequests for deployment memory resource
DefaultDeploymentMemoryResourceRequests = "512Mi"
// DefaultDeploymentMemoryResourceLimits for deployment memory resource limits
DefaultDeploymentMemoryResourceLimits = "512Mi"
// DefaultEnvoyProxyImage is the default image used by envoyproxy
DefaultEnvoyProxyImage = "docker.io/envoyproxy/envoy:distroless-dev"
// DefaultShutdownManagerCPUResourceRequests for shutdown manager cpu resource
DefaultShutdownManagerCPUResourceRequests = "10m"
// DefaultShutdownManagerMemoryResourceRequests for shutdown manager memory resource
DefaultShutdownManagerMemoryResourceRequests = "32Mi"
// DefaultShutdownManagerMemoryResourceLimits for shutdown manager memory resource limits
DefaultShutdownManagerMemoryResourceLimits = "32Mi"
// DefaultShutdownManagerImage is the default image used for the shutdown manager.
DefaultShutdownManagerImage = "docker.io/envoyproxy/gateway-dev:latest"
// DefaultRateLimitImage is the default image used by ratelimit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -155,6 +157,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -246,6 +261,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -322,6 +339,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -216,6 +231,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -292,6 +309,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why these changes happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's set based on the memory limit by default, since memory limits weren't defined before they weren't being applied

Code here

// calculateMaxHeapSizeBytes calculates the maximum heap size in bytes as 80% of Envoy container memory limits.
// In case no limits are defined '0' is returned, which means no heap size limit is set.
func calculateMaxHeapSizeBytes(envoyResourceRequirements *corev1.ResourceRequirements) uint64 {
if envoyResourceRequirements == nil || envoyResourceRequirements.Limits == nil {
return 0
}
if memLimit, ok := envoyResourceRequirements.Limits[corev1.ResourceMemory]; ok {
memLimitBytes := memLimit.Value()
return uint64(float64(memLimitBytes) * 0.8)
}
return 0
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for clarify

typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -255,6 +270,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -331,6 +348,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -246,6 +261,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -322,6 +339,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -246,6 +261,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -251,6 +266,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -327,6 +344,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -155,6 +157,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ spec:
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 429496729
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
- --drain-strategy immediate
Expand Down Expand Up @@ -248,6 +263,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 512Mi
requests:
cpu: 100m
memory: 512Mi
Expand Down Expand Up @@ -324,6 +341,8 @@ spec:
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
Expand Down
Loading