diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-05-04 00:39:13 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-05-04 00:39:13 +0200 |
| commit | 2c4af77f5f7231b560c344ccaff3cc73f0d616e9 (patch) | |
| tree | 44dbe299c49b35399fb755ef81929b32af9312fd /src/routing.c | |
| parent | bdb9db6458594d9265c86362d248e30fcf8ea26e (diff) | |
Refactor lookup init and add routing table metric
I think it would be nice to see the detailed routing table occupancy.
I've added a metric that exposes the current occupancy of each bucket.
That should provide me some insight into the current distribution of
nodes and if we need to find a way to keep the closer buckets alive.
Diffstat (limited to 'src/routing.c')
| -rw-r--r-- | src/routing.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/routing.c b/src/routing.c index edffffc..7c10e16 100644 --- a/src/routing.c +++ b/src/routing.c @@ -8,7 +8,9 @@ #include <string.h> #include <stdbool.h> #include <stdlib.h> +#include <pthread.h> #include <arpa/inet.h> +#include <prom_metric_sample_histogram.h> // The DHT routing table has a keyspace of 0 -- 2^160 split into buckets of 8. // When a bucket becomes full, we split it in half. As we further expand the @@ -56,6 +58,24 @@ void routing_init(struct nodeid* myid) { routing_flush(); } +void routing_update_metrics() { + char buf[4]; // Largest value is 157 + \0 + + struct entry *entry = pTable->table; + for(uint8_t i = 0; i < RT_IDBITS-RT_BBITS; i++) { + sprintf(buf, "%d", i); + + uint8_t filled = 0; + for(uint8_t j = 0; j < RT_BSIZE; j++) { + filled += entry->set; + entry++; + } + + prom_gauge_set(routing_table_occupied, filled, (const char*[]){buf}); + } + dbg("Update metrics!!"); +} + void routing_flush() { memset(pTable->table, 0, sizeof(pTable->table)); } @@ -159,6 +179,7 @@ void routing_remove(struct nodeid* id) { entry->set = false; entry->expire = 0; + routing_update_metrics(); } bool routing_interested(struct nodeid* id) { @@ -295,3 +316,4 @@ void routing_status(int* filled, int* size, double* load_factor, size_t load_fac load_factor[i] /= per_bucket + is_overflow; } } + |
