Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/
Database Manual
/ /

Configure the Ingress Connection Establishment Rate Limiter

This procedure describes how to configure rate limiting using the ingressConnectionEstablishmentRateLimiterEnabled parameter in MongoDB. The rate limiter helps protect your deployment from connection storms that can impact system stability and performance.

Before you begin this procedure, ensure you meet the following requirements:

  • You have administrative privileges on your MongoDB deployment

  • You understand your system's connection load patterns and requirements

  • You know your driver's connectTimeoutMS setting

1

To begin using the rate limiter, first enable it by setting the ingressConnectionEstablishmentRateLimiterEnabled parameter to true:

db.adminCommand( {
setParameter: 1,
ingressConnectionEstablishmentRateLimiterEnabled: true
} )
2

Set ingressConnectionEstablishmentRatePerSec to the maximum rate that your cluster can handle without negatively impacting throughput. This should be a fixed number that doesn't vary based on other workload dynamics.

db.adminCommand( {
setParameter: 1,
ingressConnectionEstablishmentRatePerSec: 20
} )
3

Set ingressConnectionEstablishmentMaxQueueDepth according to the following formula:

maxQueueDepth < (establishmentRatePerSec / 1000) * (connectTimeoutMs - ((averageTimeToCompletedHelloMicros-averageTimeQueuedMicros)*1000))

This formula ensures that:

  • New connection attempts do not remain in the queue past the time that the driver has abandoned them.

  • Most hello+auth attempts succeed, rather than failing due to a timeout error.

The averageTimeQueuedMicros metric can assist in tuning ingressConnectionEstablishmentMaxQueueDepth, as it equals approximately (maxQueueDepth / establishRatePerSec) * 1e6.

Important

When tuning the queue size, prioritize a longer queue size, rather than a shorter queue size. Drivers clearing their connection pools due to closed connections are a larger risk than connections remaining in the queue for too long and timing out.

4

If you observe connection failures, decrease your driver's maxPoolSize and maxConnecting settings. If you decrease these settings, the driver reuses connections, rather than opening more connections to the server during periods of increased latency, which can lead to connection storms.

Note

If you decrease maxPoolSize and maxConnecting, queries may spend a longer time at the driver layer waiting for a connection to be returned to the pool. Decreasing these settings helps maintain availability at the cost of increased latency during load spikes.

Monitor the following metrics to ensure you properly configure your rate limiter:

If you observe increasing numbers of rejected connections, consider:

  1. Increasing ingressConnectionEstablishmentRatePerSec if the cluster appears to have suffiecient CPU resources to handle this load.

  2. Adjusting ingressConnectionEstablishmentMaxQueueDepth based on the formula.

  3. Reviewing driver connection pool settings.

On this page