wasm_socket_buffer_reuse

The `wasm_socket_buffer_reuse` directive controls the reuse of buffers for WebAssembly sockets in NGINX.

Syntaxwasm_socket_buffer_reuse on | off;
Defaultoff
Contexthttp, server, location
Arguments1

Description

The wasm_socket_buffer_reuse directive enables or disables buffer reuse for WebAssembly sockets utilized in conjunction with the NGINX Proxy-Wasm module. When enabled, this feature allows the underlying memory buffers created for WebAssembly socket operations to be reused across different calls. This can lead to improved performance by minimizing memory allocation overhead and reducing the pressure on the memory allocator. The directive accepts a single argument, which is typically either 'on' or 'off', indicating whether buffer reuse should be allowed or not.

When buffer reuse is enabled, the NGINX server will manage memory more efficiently, especially in scenarios where multiple WebAssembly modules are executed in succession. However, it is essential to understand that enabling this feature can also lead to complexity in terms of memory management and debugging, particularly if the lifecycle of the buffers is not handled correctly within the WebAssembly code. As a result, ensure that the WebAssembly module properly manages its resources to avoid undefined behavior or memory leaks that may arise from improper reuse of buffers.

Config Example

http {
    server {
        listen 9000;

        location / {
            proxy_wasm my_filter;
            proxy_pass http://backend;
        }

        wasm_socket_buffer_reuse on;
    }
}

Do not enable buffer reuse if your WebAssembly modules do not properly handle buffer lifetimes, as this may lead to unexpected behavior.

Ensure that all buffer allocations made by the WebAssembly are compatible with the reuse strategy to avoid memory corruption.

← Back to all directives