echo_blocking_sleep

The `echo_blocking_sleep` directive introduces a blocking sleep period in the NGINX request processing, pausing the response for a specified duration.

Syntaxecho_blocking_sleep time;
Defaultnone
Contextlocation, if in location
Arguments1

Description

The echo_blocking_sleep directive is part of the NGINX Echo module, which adds various utility functions to the NGINX configuration. This particular directive allows the user to implement a blocking sleep interval during processing a request. When it is executed, NGINX will pause and not process further requests until the specified sleep duration has elapsed. The effect is similar to causing a delay before sending a response back to the client.

This directive takes a single argument: the duration of the sleep period, specified in seconds or milliseconds (for instance, '5' for 5 seconds or '200ms' for 200 milliseconds). During this blocking period, the request is prevented from moving to the next stages of processing in NGINX. This is particularly useful in scenarios where you want to simulate delays or throttle responses for testing or demonstration purposes.

When configuring echo_blocking_sleep, it can be set within location blocks or conditionally within if statements inside those blocks. It is important to note that it can affect performance and should generally be used judiciously, particularly in production environments, as blocking sleeps might lead to increased latency and resource use on the server.

Config Example

location /sleep_example {
    echo "Processing request...";
    echo_blocking_sleep 3;
    echo "Response after 3 seconds";
}

Using echo_blocking_sleep in a high-traffic context can lead to performance bottlenecks because it blocks worker processes.

Ensure that the sleep duration is appropriate for the desired effect; excessively long waits can degrade user experience.

← Back to all directives