From ba2a076001be6e4140fbd2703cd134e5aa51450b Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sun, 15 May 2022 15:05:13 +0200 Subject: [PATCH] BGP: Improve tx performance during feed/flush The prefix hash table in BGP used the same hash function as the rtable. When a batch of routes are exported during feed/flush to the BGP, they all have similar hash values, so they are all crowded in a few slots in the BGP prefix table (which is much smaller - around the size of the batch - and uses higher bits from hash values), making it much slower due to excessive collisions. Use a different hash function to avoid this. Also, increase the batch size to fill 4k BGP packets and increase minimum BGP bucket and prefix hash sizes to avoid back and forth resizing during flushes. This leads to order of magnitude faster flushes (on my test data). --- nest/rt-table.c | 2 +- proto/bgp/attrs.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nest/rt-table.c b/nest/rt-table.c index a10979e6..c3563171 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -2380,7 +2380,7 @@ static void rt_prune_table(rtable *tab) { struct fib_iterator *fit = &tab->prune_fit; - int limit = 512; + int limit = 2000; struct channel *c; node *n, *x; diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 1f927cbd..a9787173 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -1458,7 +1458,7 @@ bgp_finish_attrs(struct bgp_parse_state *s, rta *a) #define RBH_FN(a,h) h #define RBH_REHASH bgp_rbh_rehash -#define RBH_PARAMS /8, *2, 2, 2, 8, 20 +#define RBH_PARAMS /8, *2, 2, 2, 12, 20 HASH_DEFINE_REHASH_FN(RBH, struct bgp_bucket) @@ -1600,7 +1600,7 @@ bgp_withdraw_bucket(struct bgp_channel *c, struct bgp_bucket *b) #define PXH_FN(n,i,h) h #define PXH_REHASH bgp_pxh_rehash -#define PXH_PARAMS /8, *2, 2, 2, 8, 24 +#define PXH_PARAMS /8, *2, 2, 2, 12, 24 HASH_DEFINE_REHASH_FN(PXH, struct bgp_prefix) @@ -1626,7 +1626,8 @@ bgp_free_prefix_table(struct bgp_channel *c) static struct bgp_prefix * bgp_get_prefix(struct bgp_channel *c, net_addr *net, u32 path_id) { - u32 hash = net_hash(net) ^ u32_hash(path_id); + /* We must use a different hash function than the rtable */ + u32 hash = u32_hash(net_hash(net) ^ u32_hash(path_id)); struct bgp_prefix *px = HASH_FIND(c->prefix_hash, PXH, net, path_id, hash); if (px)