Around Go: MongoDB and Redis · 3 MIN READ
MongoDB under load: budget waiting before enlarging the pool
Separate server selection, pool checkout, query time and application queueing.
When every operation slows down, a larger pool can multiply pressure on the same database. Investigate where the deadline is spent: waiting in the application, selecting a server, checking out a connection, creating a socket or executing a query. Count all application instances and topology servers in the capacity model.
Around Go: data stores · A MAP OF THE IDEA
- Admission budget
- Pool checkout
- Indexed operation
- Latency and failure evidence
Useful when
- Separate server selection, pool checkout, query time and application queueing.
Watch out
- Client pool capacity, waiting goroutines and total deployment connections are different quantities.
Implementation & operation cost: Admission limits trade immediate overload rejection for bounded waiting; tuning requires client and server telemetry together.
Reuse a bounded shared client
A pool is associated with a server in the topology; monitoring connections add to the total. MaxPoolSize limits active pool capacity, not the number of goroutines allowed to wait. Give operations a deadline and bound application admission so overload does not become an invisible growing queue.
opts := options.Client().ApplyURI(uri).
SetMaxPoolSize(16).SetMaxConnecting(2).
SetMaxConnIdleTime(60*time.Second).SetTimeout(2*time.Second)
client, err := mongo.Connect(opts)
if err != nil { return err }These are illustrative v2 settings for a small service, not universal recommendations. Estimate total connections across all instances and topology members and compare checkout wait with query duration before changing the cap.
Use evidence from both client and database
In a development environment, inspect operation behavior with an explain plan and server metrics. Add client-side pool and command monitoring at the application boundary; avoid logging credentials, raw documents or sensitive filter values in telemetry.
db.notes.find({tenant: "demo"}).limit(20).explain("executionStats")
db.serverStatus().connections
db.serverStatus().opcountersAvailability of server metrics depends on deployment permissions and product. Correlate a time window of pool checkout wait, request errors and examined documents; a lifetime counter alone cannot explain current tail latency.
Recover without a retry storm
One overall deadline should cover queueing and attempts. Restrict retryable work and test server failover, pool saturation and slow-query recovery. Separate a deliberately slow bulk operation from latency-sensitive traffic when their budgets differ, and prefer fixing an inefficient query to adding thousands of waiting goroutines.
TAKE THIS WITH YOU
Bound admission and waiting as well as sockets, then tune using correlated request, pool and query evidence. More connections do not repair an overloaded database.
Check your understanding
What should precede a pool-size increase during high latency?
Go to the source
Progress stays in this browser. No account needed.