Envoy proxy is using too much memory
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Envoy Proxy, a popular open-source edge and service proxy designed for cloud-native applications, has gained widespread adoption due to its flexibility and powerful features. However, like many complex systems, it can sometimes exhibit a high memory footprint, which can impact application performance and resource allocation. This article delves into the potential causes of Envoy's memory consumption, provides technical explanations and examples, and offers strategies for optimizing memory usage.
Understanding Envoy's Memory Consumption
Envoy Proxy handles multiple tasks such as load balancing, health checks, routing, and protocol translation. While performing these tasks, Envoy uses various data structures and caching mechanisms which can contribute to memory usage. Key components contributing to memory usage include:
- Listener and Listener Filters: Envoy uses listeners to accept connections. Each listener can have multiple filters to inspect and manipulate network traffic.
- Clusters and Load Balancing: Envoy manages clusters, which represent upstream services. Memory is used to maintain cluster metadata, endpoints, and load balancing metrics.
- HTTP/2 and HTTP/3 Support: Supporting these protocols can consume more memory compared to HTTP/1.1 due to multiplexing and stream management overhead.
- Routing: Advanced routing features increase the complexity of configuration, leading to elevated memory demands.
- Telemetry and Metrics: Collection of logs and metrics involves storing data in memory before transmission or processing.
Common Scenarios Leading to High Memory Usage
1. Configuration Complexity
Complex configurations with numerous clusters, listeners, and routes can directly impact memory consumption. When configuring Envoy, each additional cluster or listener incurs overhead. An example is a microservices architecture where Envoy serves as a gateway with dozens of routes and endpoints which can consume substantial memory.
2. Inefficient Caching
Envoy utilizes caches for DNS resolutions, response compression, and other purposes. Default caching settings may not suit all environments. For instance, high cache sizes may lead to unnecessary memory usage especially when managing numerous short-lived connections.
3. Long-Lived TCP Connections
Managing long-lived connections can add considerable strain on memory usage. Examples include WebSocket connections that remain open, consuming resources even when idle.
4. High Number of Active Connections
Handling a vast number of concurrent connections necessitates resources to manage state and buffers. Scenarios like a surge in user traffic or attacks leading to numerous connection instantiations can cause spikes in memory usage.
Strategies for Managing Memory Consumption
- Optimize Configuration: Regularly review and streamline Envoy configurations. Avoid unnecessary routes, listeners or clusters.
- Tune Caching Parameters: Adjust cache sizes to balance memory use against performance. For example, set a TTL (time-to-live) for DNS cache that matches domain reconnection requirements.
- Connection Management: Implement connection timeouts and limits to handle long-lived and idle connections efficiently.
- Monitoring and Analysis: Use Envoy's robust telemetry capabilities to analyze memory utilization patterns and identify bottlenecks or inefficiencies.
- Load Testing: Simulate traffic loads to ensure Envoy configurations can handle the expected traffic patterns within acceptable memory limits.
- Use of Sidecar Resource Limits: When running Envoy as a sidecar in a Kubernetes setup, set memory resource limits in the pod’s deployment specification to prevent memory spikes from affecting other applications.
Key Details Table
| Factor | Explanation | Potential Solution |
| Configuration Complexity | Complex setups increase memory footprint. | Simplify configurations. |
| Inefficient Caching | Large caches consume more memory. | Adjust cache settings. |
| Long-Lived Connections | Sustained connections hold resources for extended periods. | Implement timeouts/limits. |
| High Active Connections | Traffic surges increase active connection states. | Monitor and scale appropriately. |
| HTTP/2 and HTTP/3 Support | Advanced protocols use additional resources for stream mgmt. | Evaluate protocol use case & necessity. |
Conclusion
Envoy Proxy's flexible and powerful features can lead to higher memory usage if not managed appropriately. By understanding the factors contributing to its memory consumption and applying targeted optimizations, you can ensure efficient resource use. Regular monitoring, analysis, and configuration tuning play crucial roles in maintaining optimal performance in diverse deployment environments. As with any complex system, continuous learning and adjustment are key to keeping memory footprints within acceptable boundaries.
Related reading
- Epoch counter with TensorFlow Dataset API
- Equivalent to Docker Desktop's 'host.docker.internal' in Rancher Desktop
- ERROR 2002 HY000 Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 2
- error 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 2' -- Missing /var/run/mysqld/mysqld.sock
- Equal sum subsets hybrid
- Error java.lang.OutOfMemoryError GC overhead limit exceeded
- epmd error for host myhost address (cannot connect to host/port) on windows 10
- e.printStackTrace equivalent in python

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.