retrystorm · Learn · Interview practice · Glossary · Components

Home › Interview practice › Out of Connections

Out of Connections

Blog pages run a slow query, and the database turns them away with half its CPU idle. Give it the connections it needs.

Inkwell Blogs pages now show related posts. The query behind them is slow, about 60 ms, mostly spent waiting on disk. Since it shipped, about one page in four fails with "too many connections", while the database's CPU sits at about half.

What it does

  • Read: a reader opens a post, with its related posts.
  • Write: an author edits a post.

Workload

A steady 4 000 rps, 95% reads / 5% writes, for 15 seconds, over 100 000 posts.

How to build it

The app tier is fixed: eight medium replicas behind a load balancer. The query time is fixed too. What you choose is the database: its tier and its read replicas. Each node accepts a limited number of connections:

TierConnections per nodePrice per node
Small100$0.12/h
Medium200$0.30/h
Large400$0.70/h
XLarge800$1.50/h
  1. Build the path: client, load balancer, app server, database. Run it as it is.
  2. How many queries are running at once? Multiply the queries per second by how long each takes.
  3. Give the reads enough connections, for as little as you can.

Part of Chapter 18: Connection Limits.

About · Contact · Privacy · Terms of use