diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-12 12:19:14 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-12 12:19:14 +0100 |
commit | 61a36e0d18b18ced16108608edf67f853f1e8100 (patch) | |
tree | dd877f5c6a13851b6fd45b4421ea0a807d02967b /src | |
parent | b1ea0670ad1309160d4b6f2758e12dc3dc04ac9d (diff) | |
download | rspamd-61a36e0d18b18ced16108608edf67f853f1e8100.tar.gz rspamd-61a36e0d18b18ced16108608edf67f853f1e8100.zip |
Implement connections counters
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 4 | ||||
-rw-r--r-- | src/fuzzy_storage.c | 3 | ||||
-rw-r--r-- | src/worker.c | 14 |
3 files changed, 13 insertions, 8 deletions
diff --git a/src/controller.c b/src/controller.c index 7ad504f30..32b170b76 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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); } diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 51bcc1001..3795383d3 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -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)); diff --git a/src/worker.c b/src/worker.c index d103d1660..a1fc09e97 100644 --- a/src/worker.c +++ b/src/worker.c @@ -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, |