proxy_upstream_buffer

Sets the upstream buffer size for TCP and UDP connections in the NGINX stream module.

Syntaxproxy_upstream_buffer size;
Defaultnone
Contextstream, stream server
Arguments1

Description

The proxy_upstream_buffer directive is utilized within the stream and stream server contexts of the NGINX Stream module to define the size of the buffer that stores data sent to upstream servers. This buffer allows for accumulation of data before it is forwarded to the upstream, which can optimize performance by reducing the number of system calls and improving throughput. The directive accepts a singular argument which specifies the buffer size in bytes.

In practice, setting a proxy_upstream_buffer value too low may lead to an increased number of write calls to the upstream server, as the data will be forwarded immediately after reaching the small buffer limit. Conversely, setting it too high might consume excessive memory, especially under high-load scenarios where many connections are active simultaneously. Therefore, it’s important to find a balance according to the application's requirements and the available system resources.

The syntax used to define this directive is as follows: proxy_upstream_buffer size;, where size is the amount of memory allocated for buffering. Proper configuration of this directive can help in tuning the performance of TCP and UDP applications served by NGINX, particularly in high-performance settings or situations involving encapsulated protocols.

Config Example

stream {
    server {
        listen 12345;
        proxy_pass backend;
        proxy_upstream_buffer 512k;
    }
    upstream backend {
        server backend1.example.com:1234;
        server backend2.example.com:1234;
    }
}

Setting the buffer size too low can cause excessive system calls, negatively impacting performance.

Allocating a buffer size too high may lead to high memory usage during peak traffic, potentially depleting system resources.

← Back to all directives