]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: worker.id and worker.count documented
authorMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 8 Dec 2015 11:57:34 +0000 (12:57 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 8 Dec 2015 11:57:34 +0000 (12:57 +0100)
daemon/README.rst
daemon/main.c
daemon/worker.h

index 72d42cefdd3ac50606e19ac603483106dd8c4307..4fccf6f66eac9c06efe7fa08f2224d29d398fec5 100644 (file)
@@ -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()
 
index 37f9ae0f3ccd24f89018c621b35763e353ad31cf..ba653431e93b9c905b4bd724c76d055ddca2c194 100644 (file)
@@ -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;
index 92a1c2f3b72d74a311f1232f74cca8cab8a58565..00a67a56bed24fd2ee27163a3c2cbe4e142e82f2 100644 (file)
@@ -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