Skip to content

Commit

Permalink
feat(env): set maxreaders greater than the number nginx worker proces…
Browse files Browse the repository at this point in the history
…ses.
  • Loading branch information
Oyami-Srk committed Nov 6, 2024
1 parent 890b3ca commit 9a4e355
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ngx_lua_resty_lmdb_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#define NGX_LUA_RESTY_LMDB_FILE_MODE 0600
#define NGX_LUA_RESTY_LMDB_DIR_MODE 0700

/* 126 is the default number of max readers in LMDB */
#define NGX_LUA_RESTY_LMDB_DEFAULT_READERS 126
#define NGX_LUA_RESTY_LMDB_MAX_READERS_REDUNDANCY 16

#define NGX_LUA_RESTY_LMDB_VALIDATION_KEY "validation_tag"

Expand Down Expand Up @@ -222,11 +225,30 @@ ngx_lua_resty_lmdb_open_file(ngx_cycle_t *cycle,
{
int rc;
int dead;
size_t readers;
ngx_core_conf_t *ccf;

if (ngx_lua_resty_lmdb_create_env(cycle, lcf, is_master) != NGX_OK) {
return NGX_ERROR;
}

/* Set max readers depending on the number of worker processes */
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
readers = (size_t)ccf->worker_processes;
readers = readers > NGX_LUA_RESTY_LMDB_DEFAULT_READERS ?
(readers + NGX_LUA_RESTY_LMDB_MAX_READERS_REDUNDANCY)
: NGX_LUA_RESTY_LMDB_DEFAULT_READERS;
rc = mdb_env_set_maxreaders(lcf->env, readers);
if (rc != 0) {
ngx_log_error(NGX_LOG_CRIT, cycle->log, 0,
"unable to set max readers for LMDB environment: %s",
mdb_strerror(rc));
mdb_env_close(lcf->env);
lcf->env = NULL;

return NGX_ERROR;
}

rc = mdb_env_open(lcf->env, (const char *) lcf->env_path->name.data,
0, NGX_LUA_RESTY_LMDB_FILE_MODE);

Expand Down

0 comments on commit 9a4e355

Please sign in to comment.