|
|
|
|
|
by 10000truths
778 days ago
|
|
"poll every N seconds" for readiness checks is an anti-pattern. The problem is that latency cascades. A dependency chain of M services will have an end-to-end latency of N*M in the worst case and (N*M/2) in the average case, if they all rely on polling to check that the next service is ready. You should instead rely on backpressure to signal readiness. A service accepts connections immediately, and only blocks the client when the service has to block on something else to procure a response. Systemd takes this approach with UNIX sockets - it creates all the UNIX sockets for each service, and then starts all the services in parallel. The socket buffers queue the messages so that clients can send messages to services that haven't yet started, and the OS scheduler will saturate the available CPU/IO so that the startup of all the services are maximally parallelized. Obviously, this is not always feasible, especially in cases where you don't control the service(s) you depend on. But to the extent that you do, relying on backpressure instead of polling can markedly improve end-to-end latency. |
|