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.
This commit is contained in:
Heikki Hannikainen 2020-09-06 13:51:09 +03:00
parent 3a445ac54e
commit 18da32f888
3 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);