From: Ondřej Kuzník Date: Wed, 10 Mar 2021 16:22:34 +0000 (+0000) Subject: ITS#9599 Online latency tracking X-Git-Tag: OPENLDAP_REL_ENG_2_6_0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d95cc3935908b7adb77eb5c20e05457d509cd99;p=thirdparty%2Fopenldap.git ITS#9599 Online latency tracking --- diff --git a/servers/lloadd/tier_bestof.c b/servers/lloadd/tier_bestof.c index 393258053e..a598d5f832 100644 --- a/servers/lloadd/tier_bestof.c +++ b/servers/lloadd/tier_bestof.c @@ -57,8 +57,27 @@ bestof_cmp( const void *left, const void *right ) { const LloadBackend *l = left; const LloadBackend *r = right; + struct timeval now; + uintptr_t count, diff; + float a = l->b_fitness, b = r->b_fitness, factor = 1; + + gettimeofday( &now, NULL ); + /* We assume this is less than a second after the last update */ + factor = 1 / ( pow( ( 1 / factor ) + 1, now.tv_usec / 1000000.0 ) - 1 ); + + count = __atomic_load_n( &l->b_operation_count, __ATOMIC_RELAXED ); + diff = __atomic_load_n( &l->b_operation_time, __ATOMIC_RELAXED ); + if ( count ) { + a = ( a * factor + (float)diff * l->b_weight / count ) / ( factor + 1 ); + } + + count = __atomic_load_n( &r->b_operation_count, __ATOMIC_RELAXED ); + diff = __atomic_load_n( &r->b_operation_time, __ATOMIC_RELAXED ); + if ( count ) { + b = ( b * factor + (float)diff * r->b_weight / count ) / ( factor + 1 ); + } - return l->b_fitness - r->b_fitness; + return (a - b < 0) ? -1 : (a - b == 0) ? 0 : 1; } LloadTier *