preread_buffer_size

Sets the size of the buffer for reading initial data in stream modules.

Syntaxpreread_buffer_size size;
Default16k
Contextstream, stream server
Arguments1

Description

The 'preread_buffer_size' directive in NGINX Stream Core defines the size of the buffer used to read the initial data from the socket before the connection is handed over to a backend server. This buffer size is crucial for protocols that require reading a certain amount of data to process a request properly or to determine the required backend server based on the initial data received.

By default, the buffer size is set to 16k, but it can be adjusted according to the specific needs of the application. If the buffer is too small, it can lead to truncated data reads, causing issues in request processing or incorrect routing to backend servers. Increasing the buffer size can help accommodate larger initial packets without risking data loss, while too large a value can consume unnecessary memory, especially when handling many concurrent connections.

It is typically declared within the 'stream' or 'stream server' contexts, allowing users to specify different sizes for different circumstances as dictated by their architecture. Careful consideration should be given to balance performance and memory usage when tuning this directive.

Config Example

stream {
    server {
        listen 1234;
        preread_buffer_size 32k;
    }
}

Setting the buffer size too small may cause issues with larger initial requests, leading to potential request failures.

A value that is too large can introduce unnecessary memory overhead, particularly when serving a large number of concurrent streams.

← Back to all directives