From: Arran Cudbard-Bell Date: Wed, 19 Jan 2022 19:23:58 +0000 (-0500) Subject: Reduce spurious rebalancing in the trunk X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f08e299f62e3d4789a3ba81f7c5e2c13d34ceaa6;p=thirdparty%2Ffreeradius-server.git Reduce spurious rebalancing in the trunk --- diff --git a/src/lib/server/trunk.c b/src/lib/server/trunk.c index 8428e553e9..931e19c791 100644 --- a/src/lib/server/trunk.c +++ b/src/lib/server/trunk.c @@ -4608,10 +4608,14 @@ static int8_t _trunk_connection_order_by_shortest_queue(void const *one, void co { fr_trunk_connection_t const *a = talloc_get_type_abort_const(one, fr_trunk_connection_t); fr_trunk_connection_t const *b = talloc_get_type_abort_const(two, fr_trunk_connection_t); + uint32_t a_count = fr_trunk_request_count_by_connection(a, FR_TRUNK_REQUEST_STATE_ALL); uint32_t b_count = fr_trunk_request_count_by_connection(b, FR_TRUNK_REQUEST_STATE_ALL); - return CMP(a_count, b_count); + /* + * Add a fudge factor of 1 to reduce spurious rebalancing + */ + return ((a_count > b_count) && ((a_count - b_count) > 1)) - ((b_count > a_count) && ((b_count - a_count) > 1)); } /** Free a trunk, gracefully closing all connections.