From 18da32f888105fbe9cd2cff2457ac5c60e47e8a0 Mon Sep 17 00:00:00 2001 From: Heikki Hannikainen Date: Sun, 6 Sep 2020 13:51:09 +0300 Subject: [PATCH] Disable historydb inserts if there are no listeners with filtering enabled. Reduces memory use, since we don't need to store the last positions of all active stations. --- src/accept.c | 7 +++++++ src/dupecheck.c | 15 +++++++++++---- src/dupecheck.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/accept.c b/src/accept.c index b5a0b9b..791c6bf 100644 --- a/src/accept.c +++ b/src/accept.c @@ -1447,6 +1447,7 @@ void accept_thread(void *asdf) acceptpl = hmalloc(poll_n * sizeof(*acceptpl)); n = 0; + int has_filtered_listeners_now = 0; for (l = listen_list; (l); l = l->next) { /* The accept thread does not poll() UDP sockets for core peers. * Worker 0 takes care of that, and processes the incoming packets. @@ -1464,6 +1465,9 @@ void accept_thread(void *asdf) fd = l->fd; } + if ((l->filter_s) || (l->client_flags & CLFLAGS_USERFILTEROK)) + has_filtered_listeners_now = 1; + hlog(LOG_DEBUG, "... %d: fd %d (%s)", n, fd, l->addr_s); acceptpfd[n].fd = fd; acceptpfd[n].events = POLLIN|POLLPRI|POLLERR|POLLHUP; @@ -1471,6 +1475,9 @@ void accept_thread(void *asdf) n++; } hlog(LOG_INFO, "Accept thread ready."); + historydb_enabled = has_filtered_listeners_now; + if (!historydb_enabled) + hlog(LOG_INFO, "Disabled historydb, listeners do not have filtering enabled."); /* stop the dupechecking and uplink threads while adjusting * the amount of workers... they walk the worker list, and diff --git a/src/dupecheck.c b/src/dupecheck.c index 13451ce..eb42b1d 100644 --- a/src/dupecheck.c +++ b/src/dupecheck.c @@ -40,6 +40,8 @@ int dupecheck_running; pthread_t dupecheck_th; long dupecheck_cellgauge; +int historydb_enabled; /* historydb inserts enabled only if filtering available */ + int pbuf_global_count; int pbuf_global_dupe_count; @@ -649,10 +651,15 @@ static int dupecheck_drain_worker(struct worker_t *w, pbnext = pb->next; // it may get modified below.. if (rc == 0) { - // put non-duplicate packet in history database - // and let filter module do it's thing - historydb_insert(pb); - filter_postprocess_dupefilter(pb); + /* put non-duplicate packet in history database + * and let filter module do it's thing, if historydb + * is enabled (disabled if no filtered listeners + * configured, for memory savings) + */ + if (historydb_enabled) { + historydb_insert(pb); + filter_postprocess_dupefilter(pb); + } // Not duplicate **pb_out_prevp = pb; diff --git a/src/dupecheck.h b/src/dupecheck.h index 40acfdd..2c1f331 100644 --- a/src/dupecheck.h +++ b/src/dupecheck.h @@ -41,6 +41,7 @@ extern long long dupecheck_dupecount; /* statistics counter */ extern long long dupecheck_dupetypes[DTYPE_MAX+1]; extern long dupecheck_cellgauge; /* statistics gauge */ +extern int historydb_enabled; extern int dupecheck_eventfd; extern int outgoing_lag_report(struct worker_t *self, int*lag, int*dupelag);