]> source.dussan.org Git - rspamd.git/commitdiff
Implement connections counters
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Oct 2015 11:19:14 +0000 (12:19 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Oct 2015 11:19:14 +0000 (12:19 +0100)
src/controller.c
src/fuzzy_storage.c
src/worker.c

index 7ad504f30e3f882448aa20819f737b682f4484a7..32b170b7641226cf0a818fd77824dc3a9082c671 100644 (file)
@@ -177,6 +177,7 @@ struct rspamd_controller_worker_ctx {
 
 struct rspamd_controller_session {
        struct rspamd_controller_worker_ctx *ctx;
+       struct rspamd_worker *wrk;
        rspamd_mempool_t *pool;
        struct rspamd_task *task;
        struct rspamd_classifier_config *cl;
@@ -2018,6 +2019,7 @@ rspamd_controller_finish_handler (struct rspamd_http_connection_entry *conn_ent)
                rspamd_mempool_delete (session->pool);
        }
 
+       session->wrk->nconns --;
        rspamd_inet_address_destroy (session->from_addr);
        msg_debug_session ("destroy session %p", session);
        g_slice_free1 (sizeof (struct rspamd_controller_session), session);
@@ -2050,6 +2052,8 @@ rspamd_controller_accept_socket (gint fd, short what, void *arg)
        session->ctx = ctx;
 
        session->from_addr = addr;
+       session->wrk = worker;
+       worker->nconns ++;
 
        rspamd_http_router_handle_socket (ctx->http, nfd, session);
 }
index 51bcc1001e0d81c700b0450a0d0cb5f4dfd0c5e4..3795383d35d0145e5012ec17fadf77791ce7033a 100644 (file)
@@ -386,6 +386,8 @@ accept_fuzzy_socket (gint fd, short what, void *arg)
 
        /* Got some data */
        if (what == EV_READ) {
+               worker->nconns++;
+
                while ((r = rspamd_inet_address_recvfrom (fd, buf, sizeof (buf), 0,
                        &session.addr)) == -1) {
                        if (errno == EINTR) {
@@ -408,6 +410,7 @@ accept_fuzzy_socket (gint fd, short what, void *arg)
                }
 
                rspamd_inet_address_destroy (session.addr);
+               worker->nconns --;
        }
 
        rspamd_explicit_memzero (session.nm, sizeof (session.nm));
index d103d16601e1f52f73a54738c5737c83309475b3..a1fc09e970aae4d03fb83d7ab5b1324bad94cb77 100644 (file)
@@ -92,8 +92,6 @@ struct rspamd_worker_ctx {
        gboolean allow_learn;
        /* DNS resolver */
        struct rspamd_dns_resolver *resolver;
-       /* Current tasks */
-       guint32 tasks;
        /* Limit of tasks */
        guint32 max_tasks;
        /* Events base */
@@ -112,9 +110,9 @@ struct rspamd_worker_ctx {
 static void
 reduce_tasks_count (gpointer arg)
 {
-       guint32 *tasks = arg;
+       guint *nconns = arg;
 
-       (*tasks)--;
+       (*nconns)--;
 }
 
 static gint
@@ -192,9 +190,9 @@ accept_socket (gint fd, short what, void *arg)
 
        ctx = worker->ctx;
 
-       if (ctx->max_tasks != 0 && ctx->tasks > ctx->max_tasks) {
+       if (ctx->max_tasks != 0 && worker->nconns > ctx->max_tasks) {
                msg_info_ctx ("current tasks is now: %uD while maximum is: %uD",
-                       ctx->tasks,
+                               worker->nconns,
                        ctx->max_tasks);
                return;
        }
@@ -237,9 +235,9 @@ accept_socket (gint fd, short what, void *arg)
                RSPAMD_HTTP_SERVER,
                ctx->keys_cache);
        task->ev_base = ctx->ev_base;
-       ctx->tasks++;
+       worker->nconns++;
        rspamd_mempool_add_destructor (task->task_pool,
-               (rspamd_mempool_destruct_t)reduce_tasks_count, &ctx->tasks);
+               (rspamd_mempool_destruct_t)reduce_tasks_count, &worker->nconns);
 
        /* Set up async session */
        task->s = rspamd_session_create (task->task_pool, rspamd_task_fin,