shm_kv

The `shm_kv` directive allows the definition of a shared memory key-value storage for use in NGINX with the Wasm module.

Syntaxshm_kv name size [expire];
Defaultnone
Context
Arguments2-3

Description

The shm_kv directive in the NGINX Proxy-Wasm module facilitates the creation of a shared memory key-value storage mechanism. This directive is useful for storing data that requires quick access and can be shared among different worker processes, enabling fast inter-worker communication without relying on external databases. When defined, this memory space can be accessed and manipulated by WebAssembly modules running within NGINX, allowing developers to implement caching strategies, session storage, or application state management within their WebAssembly logic.

The shm_kv directive takes two or three parameters: the name of the shared memory area, the size of the memory area, and an optional third parameter which can define the keys' expiration policy in seconds. The key-space defined by this directive becomes accessible to all instances of the application that run within NGINX, ensuring that data is shared across requests and users efficiently. It is vital to manage this shared memory judiciously, as excessive usage may lead to performance bottlenecks or memory allocation issues across worker processes.

Config Example

shm_kv my_shared_memory 128m;

Using the shm_kv directive without proper memory size allocation can lead to unexpected behavior or crashes.

Ensure that the shared memory size is sufficient for your needs to avoid running into memory allocation errors.

Overusing shared memory may lead to contention and performance degradation amongst worker processes.

← Back to all directives