Practical System Design

Labs / Chapter 2

The connection stays held while the payload is built

Start from the chapter estimate of 400 lookups a second and a 70 ms query. Raise payload work while the connection is held, and watch pending acquisitions climb. Then move that work to before the acquire and let the queue finish.

The system

Little's Law gives 28.0 busy connections: 400 lookups a second times 70 ms. The chapter's 400 by 70 ms estimate is 28 of 40.

recommendacquirequery

Product Page

Catalog stays here

Recommendation

Payload built while holding the connection

Pool

28.0 of 40 busy

Database

Query 70 ms

pool.acquire

  1. # lookups/s = query_ms = payload_ms = pool = 40
  2. hold_during_build =
  3. with pool.acquire() as conn:
  4. payload = build_payload(request)
  5. result = query_database(conn, payload)
  6. payload = build_payload(request)
  7. with pool.acquire() as conn:
  8. result = query_database(conn, payload)
  1. AcquirePending 0 on a pool of 40
  2. build_payload0 ms while the connection is held
  3. Query70 ms. Average 28.0 of 40

Average connections against the pool of 40

The line is L = λW. Pending acquisitions are in the metrics once the average passes 40.

Average 28.0 · Pending 0.0

The chart fills as the lab runs. connections is the vertical unit.

  • Average
  • Pending
  • connections