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.
pool.acquire
- # lookups/s = query_ms = payload_ms = pool = 40
- hold_during_build =
- with pool.acquire() as conn:
- payload = build_payload(request)
- result = query_database(conn, payload)
- payload = build_payload(request)
- with pool.acquire() as conn:
- result = query_database(conn, payload)
- AcquirePending 0 on a pool of 40
- build_payload0 ms while the connection is held
- 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
