sqlitelog_async
The `sqlitelog_async` directive configures the usage of an asynchronous thread pool for logging NGINX requests to an SQLite database.
Description
The sqlitelog_async directive allows NGINX to log request information to an SQLite database using a thread pool, which enhances performance by allowing logging operations to be processed in the background rather than blocking the request-handling threads. This can be beneficial for high-traffic environments where synchronous logging may introduce latency. The directive requires a single argument to specify the name of the thread pool that it should use, which must be previously defined in the NGINX configuration.
When this directive is set, NGINX will enqueue logging tasks to the designated thread pool, enabling multiple log entries to be processed simultaneously. This not only improves the efficiency of the logging process but also helps to avoid logger bottlenecks during peak traffic periods. However, using this feature requires that NGINX is compiled with thread support (NGX_THREADS) enabled; otherwise, the directive will not function as expected. Logging formats and the overall logging setup must also be properly configured to take full advantage of this directive.
The performance benefit depends on the manner in which the thread pool is configured (in terms of size and workload). The thread pool can be defined using the thread_pool directive, and its optimal configuration can vary based on server load and specific application requirements.
Config Example
http {
thread_pool my_pool threads=4 max_queue=512;
sqlitelog_async my_pool;
sqlitelog_format myformat $remote_addr $status;
sqlitelog /path/to/log.db myformat;
}Ensure that the thread pool is defined before using sqlitelog_async.
NGINX must be compiled with thread support; otherwise, the directive will have no effect.
Be mindful of database contention if the logging frequency is excessively high.