you can see the statistics or schedule new queries. It also contains information about
specified worker count and process rank.
+.. envvar:: worker.id
+
+ Value from environment variable ``SYSTEMD_INSTANCE``,
+ or if it is not set, :envvar:`PID <worker.pid>` (string).
+
.. envvar:: worker.pid
Current worker process PID (number).
-
.. function:: worker.stats()
Return table of statistics. See member descriptions in :c:type:`worker_stats`.
#include <lauxlib.h>
#include <libknot/packet/pkt.h>
#include <libknot/descriptor.h>
+#include <contrib/cleanup.h>
#include <contrib/ucw/lib.h>
#include <contrib/ucw/mempool.h>
#include <contrib/wire.h>
the_worker = NULL;
}
-int worker_init(struct engine *engine, int worker_id, int worker_count)
+int worker_init(struct engine *engine, int worker_count)
{
assert(engine && engine->L);
assert(the_worker == NULL);
uv_loop_t *loop = uv_default_loop();
worker->loop = loop;
- worker->id = worker_id;
worker->count = worker_count;
/* Register table for worker per-request variables */
/* Set some worker.* fields in Lua */
lua_getglobal(engine->L, "worker");
- lua_pushnumber(engine->L, worker_id);
+ pid_t pid = getpid();
+
+ auto_free char *pid_str = NULL;
+ const char *inst_name = getenv("SYSTEMD_INSTANCE");
+ if (inst_name) {
+ lua_pushstring(engine->L, inst_name);
+ } else {
+ ret = asprintf(&pid_str, "%ld", (long)pid);
+ assert(ret > 0);
+ lua_pushstring(engine->L, pid_str);
+ }
lua_setfield(engine->L, -2, "id");
- lua_pushnumber(engine->L, getpid());
+
+ lua_pushnumber(engine->L, pid);
lua_setfield(engine->L, -2, "pid");
lua_pushnumber(engine->L, worker_count);
lua_setfield(engine->L, -2, "count");
/** Create and initialize the worker.
* \return error code (ENOMEM) */
-int worker_init(struct engine *engine, int worker_id, int worker_count);
+int worker_init(struct engine *engine, int worker_count);
/** Destroy the worker (free memory). */
void worker_deinit(void);
struct worker_ctx {
struct engine *engine;
uv_loop_t *loop;
- int id;
- int count;
+ int count; /** unreliable, does not count systemd instance, do not use */
int vars_table_ref;
unsigned tcp_pipeline_max;
==========
Users
-~~~~~
+-----
* Users of :ref:`control-sockets` API need to terminate each command sent to resolver with newline
character (ASCII ``\n``). Correct usage: ``cache.stats()\n``.
Newline terminated commands are accepted by all resolver versions >= 1.0.0.
+Configuration file
+------------------
+
+* Lua variable :envvar:`worker.id` is now a string with either Systemd instance name or PID
+ (instead of number). If your custom configuration uses :envvar:`worker.id` value please
+ check your scripts.
+
Module changes
--------------
* Reply packet :c:type:`kr_request.answer`