js_fetch_buffer_size

The js_fetch_buffer_size directive controls the maximum size of the buffer for fetching JavaScript responses in NGINX.

Syntaxjs_fetch_buffer_size size;
Defaultnone
Contextstream, stream server
Arguments1

Description

The js_fetch_buffer_size directive is configured within NGINX to specify the maximum size of the buffer that holds data fetched by JavaScript. This buffer is critical when executing scripts that involve the njs dynamic module, allowing for efficient data handling during requests that process JavaScript logic. When the allocated buffer reaches this size, NGINX can perform actions such as triggering additional processing or returning an error, thus preventing excessive resource usage or preventing a response from becoming unmanageable.

This directive accepts a single argument, which defines the buffer size. The size can be specified in standard sizes such as bytes, kilobytes, megabytes, etc., and NGINX will handle this accordingly. It is essential to set this value appropriately based on the expected data payload sizes in requests involving JavaScript processing to prevent unexpected behaviors or performance dips due to constrained resources. For example, if your application processes large JSON payloads, setting a larger buffer size can lead to better performance and reduced latency since it allows more data to be handled in memory before any processing occurs.

Care should be taken when tuning js_fetch_buffer_size, as a buffer that is too small may cause NGINX to drop connections or return errors on larger payloads, while a buffer that is excessively large could lead to wasted memory resources. Furthermore, tweaking this directive is often done in conjunction with other memory management settings within NGINX to ensure an optimal performance balance.

Config Example

js_fetch_buffer_size 16k;

Setting a buffer size too low may result in dropped responses or errors on larger data sets.

An excessively high buffer size could adversely affect memory usage and overall system performance.

← Back to all directives