js_fetch_max_response_buffer_size
Sets the maximum buffer size for responses in the NGINX njs dynamic modules.
Description
The js_fetch_max_response_buffer_size directive is used to configure the maximum size of the response buffer when fetching data using NGINX's njs (JavaScript) module. This directive is essential for controlling memory usage during operations that involve large amounts of data, namely when the server needs to handle substantial response bodies from upstream servers or during internal fetches within the server-side JavaScript execution. By limiting the maximum buffer size, users can ensure that their applications do not consume excess memory and can maintain stable performance under load.
This directive accepts a single argument that specifies the size of the buffer. The value can be defined in various formats such as bytes (e.g., 1m, 512k, 128, etc.). If the response exceeds this defined size, NGINX will truncate the response at the configured limit, preventing potential memory overflow and ensuring that the server remains responsive. Setting an appropriate size is vital; a value that is too small may lead to incomplete responses, while a size that is excessively high may lead to unnecessary memory consumption.
The js_fetch_max_response_buffer_size directive can be set in the stream and stream server contexts, which are commonly utilized for TCP/UDP traffic and provide facilities for applying NGINX configurations at the transport layer. Properly managing this directive is crucial for optimizing performance and resource allocation, especially in environments with variable response sizes or high traffic.
Config Example
stream {
js_fetch_max_response_buffer_size 1m;
server {
# other server directives
}
}Setting the buffer size too low may lead to truncated responses.
Not all contexts or configurations may support this directive, ensure compatibility.
If not set, default behavior could lead to excessive memory usage for large responses.