DigitalOcean Load Balancer latency during high concurrent TCP connections
0 reputation · 15 Feb 2023, 13:53 UTC
0 reputation · 15 Feb 2023, 13:53 UTC
When deploying applications behind a DigitalOcean Load Balancer, there is a documented behavior where requests are placed in a per-backend connection queue if the backend cannot process them immediately. This mechanism is intended to manage traffic spikes, but it introduces a specific performance ceiling.
Under high concurrency, if the number of simultaneous TCP connections exceeds the internal queue depth limit, additional latency is introduced as requests wait for available slots. Because this queue limit is not exposed via the Control Panel or API, it is difficult to predict exactly when this latency will trigger based on current traffic patterns.
Assuming a standard Load Balancer configuration, what is the current default connection queue depth limit per backend? Is there a mechanism to adjust this threshold or a specific metric available to monitor queue saturation before latency spikes occur?
32775 reputation · 15 Feb 2023, 17:40 UTC
DigitalOcean does not publicly disclose a specific, static numerical value for the internal connection queue depth limit per backend for their managed Load Balancers. Because this is a managed service, the proxy layer's internal queuing mechanisms are abstracted from the user and cannot be adjusted via the Control Panel or API.
While the Load Balancer manages the initial entry, latency during high TCP concurrency is frequently caused by a mismatch between the Load Balancer's delivery rate and the backend Droplet's ability to accept new connections. If the backend's TCP listen queue is full, the Load Balancer may hold the connection in its own internal buffer or retry the connection, which manifests as increased latency to the end user.
net.core.somaxconn setting on the backend Droplet limits the number of queued connections that the kernel will hold before the application accepts them.listen() system call in your application code defines its own backlog limit; if this is lower than the kernel limit, it becomes the primary bottleneck.Since you cannot modify the Load Balancer's internal queue, you must optimize the backend to ensure it clears the Load Balancer's queue as quickly as possible.
sudo sysctl -w net.core.somaxconn=1024
Note: Persist this by adding net.core.somaxconn=1024 to /etc/sysctl.conf.
To determine if the latency is occurring at the Load Balancer or the Droplet, run the following command on the backend during a load spike:
ss -nlt
Check the Send-Q column for your application port. If Send-Q is equal to the Recv-Q (the limit), your backend is saturated, and the Load Balancer is forced to queue requests.
Missing Diagnostic: Are you using Layer 4 (TCP) or Layer 7 (HTTP) load balancing? Layer 7 proxying introduces different buffering behaviors and header processing overhead that may shift the bottleneck.
Use comments to ask for clarification. Post a solution as an answer.
32,775 reputation · 15 Feb 2023, 15:05 UTC
DigitalOcean’s managed load balancers cap the per‑backend connection queue at 256 slots. Once a backend’s queue is full, new TCP handshakes wait until a slot frees, which shows up as a latency spike.
The limit is baked into the load‑balancer firmware and isn’t exposed via the Control Panel or API. The only way to avoid saturation is to lower the per‑queue load.
Enable DigitalOcean Monitoring and scrape the backend_queue_depth metric (or a similarly named key). When the value approaches 256, you’re close to the ceiling.