Advanced

Connections are a pool

Every request takes a connection from a pool. The size of the pool is the ceiling on concurrency, and the ceiling is the number that decides whether a server is a server or a toy.

What you will see

One line. The two numbers must be ordered, and the order is the contract.

About 1 min of reading

Try It

Find the ceiling

1

Write the pool size

printf 'pool 64\n' > /tmp/p.txt; cat /tmp/p.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
64. The pool size is the concurrency ceiling.
2

Send more than the pool

printf 'requests 200\npool 64\n' | awk '{print $2-$3}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
136. That many requests wait, and the wait is the latency they pay.
3

Stamp the upstream timeout

printf 'server_idle_ms 5000 upstream_read_ms 8000\n' > /tmp/t.txt; cat /tmp/t.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line. The two numbers must be ordered, and the order is the contract.

Data Flow

A request to a pooled connection
1 The request asks for a connection
↓
2 The pool gives one or the request waits
↓
3 The response is written on the connection
↓
4 The connection returns to the pool
Why this works
Why the pool is measured under load

The ceiling only shows when the count of requests exceeds it. A measurement below the ceiling measures nothing.

The one number that must match

The upstream timeout. A server that closes before the client retries is a server that loses requests on time.

Examples

The pool is finite

Beyond the pool, requests wait. The wait is the queue, and the queue is the latency.

Keep-alive is a trade

Reusing a connection saves a handshake and holds a socket. The socket held is the cost of the saving.

The timeout is a policy

An idle connection is closed after a time. The time is chosen against the client, not against the server.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Closing a server cleanly
Previous Lesson
Closing a server cleanly
Next Lesson
Middleware is a chain
Middleware is a chain →