Commit 110f5e49 authored by Marek Vavruša's avatar Marek Vavruša

daemon: worker.id and worker.count documented

parent 77e781a8
......@@ -715,7 +715,16 @@ Scripting worker
^^^^^^^^^^^^^^^^
Worker is a service over event loop that tracks and schedules outstanding queries,
you can see the statistics or schedule new queries.
you can see the statistics or schedule new queries. It also contains information about
specified worker count and process rank.
.. envvar:: worker.count
Return current total worker count (e.g. `1` for single-process)
.. envvar:: worker.id
Return current worker ID (starting from `0` up to `worker.count - 1`)
.. function:: worker.stats()
......
......@@ -140,7 +140,7 @@ static void help(int argc, char *argv[])
" [rundir] Path to the working directory (default: .)\n");
}
static struct worker_ctx *init_worker(uv_loop_t *loop, struct engine *engine, mm_ctx_t *pool, int worker_id)
static struct worker_ctx *init_worker(uv_loop_t *loop, struct engine *engine, mm_ctx_t *pool, int worker_id, int worker_count)
{
/* Load bindings */
engine_lualib(engine, "modules", lib_modules);
......@@ -155,6 +155,8 @@ static struct worker_ctx *init_worker(uv_loop_t *loop, struct engine *engine, mm
return NULL;
}
memset(worker, 0, sizeof(*worker));
worker->id = worker_id;
worker->count = worker_count;
worker->engine = engine,
worker->loop = loop;
loop->data = worker;
......@@ -165,6 +167,8 @@ static struct worker_ctx *init_worker(uv_loop_t *loop, struct engine *engine, mm
lua_getglobal(engine->L, "worker");
lua_pushnumber(engine->L, worker_id);
lua_setfield(engine->L, -2, "id");
lua_pushnumber(engine->L, worker_count);
lua_setfield(engine->L, -2, "count");
lua_pop(engine->L, 1);
return worker;
}
......@@ -306,6 +310,7 @@ int main(int argc, char **argv)
kr_crypto_init();
/* Fork subprocesses if requested */
int fork_count = forks;
while (--forks > 0) {
int pid = fork();
if (pid < 0) {
......@@ -338,7 +343,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
/* Create worker */
struct worker_ctx *worker = init_worker(loop, &engine, &pool, forks);
struct worker_ctx *worker = init_worker(loop, &engine, &pool, forks, fork_count);
if (!worker) {
log_error("[system] not enough memory\n");
return EXIT_FAILURE;
......
......@@ -32,6 +32,8 @@ typedef array_t(void *) mp_freelist_t;
struct worker_ctx {
struct engine *engine;
uv_loop_t *loop;
int id;
int count;
#if __linux__
uint8_t wire_buf[RECVMMSG_BATCH * KNOT_WIRE_MAX_PKTSIZE];
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment