socket_buffer_size

The `wasm_socket_buffer_size` directive sets the size of the socket buffer for Wasm modules in NGINX.

Syntaxwasm_socket_buffer_size size;
Defaultnone
Context
Arguments1

Description

The wasm_socket_buffer_size directive is part of the NGINX Proxy-Wasm module that allows users to set the buffer size for socket communications handled by WebAssembly (Wasm) modules. When the directive is specified, it configures the amount of memory allocated for the buffer used during socket operations such as reading from or writing to sockets. This can help optimize performance based on the expected data load and interactions with upstream servers or clients.

The directive accepts a single argument that specifies the buffer size, which can be defined using standard size suffixes (e.g., k for kilobytes, m for megabytes), allowing for a range of sizes to be configured based on application needs. Properly setting this value can ensure that sockets do not become bottlenecks during high-throughput scenarios, particularly in environments where latency-sensitive operations occur frequently. Misconfiguration or defaults that are too low may lead to dropped packets or failed requests, while excessively large buffer sizes may lead to inefficient memory usage.

It is important to include wasm_socket_buffer_size within the http block of your NGINX configuration, and it remains in effect for all Wasm modules instantiated in that context. Thus, decisions about buffer sizes should consider the collective demands placed on the socket system by the deployed Wasm modules.

Config Example

http {
    wasm_socket_buffer_size 8k;
    # Further configuration for Wasm modules... 
}

Ensure the buffer size is set within the http context, as placing it elsewhere will cause an error.

Avoid setting buffer sizes that are significantly larger than the typical network payloads, as this may waste memory.

Consider the performance trade-offs between latency and throughput when selecting your buffer size.

← Back to all directives