From: Ondřej Kuzník Date: Wed, 10 Mar 2021 16:17:33 +0000 (+0000) Subject: ITS#9599 Push based latency tracking X-Git-Tag: OPENLDAP_REL_ENG_2_6_0~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8219a3a414f232512b549af323e1aeae3043e824;p=thirdparty%2Fopenldap.git ITS#9599 Push based latency tracking --- diff --git a/servers/lloadd/lload.h b/servers/lloadd/lload.h index ec6c9d0c0f..85b4d6761f 100644 --- a/servers/lloadd/lload.h +++ b/servers/lloadd/lload.h @@ -313,6 +313,9 @@ struct LloadBackend { uintptr_t b_fitness; int b_weight; + uintptr_t b_operation_count; + uintptr_t b_operation_time; + #ifdef BALANCER_MODULE monitor_subsys_t *b_monitor; #endif /* BALANCER_MODULE */ @@ -476,9 +479,6 @@ struct LloadConnection { TAvlnode *c_ops; /* Operations pending on the connection */ - uintptr_t c_operation_count; - uintptr_t c_operation_time; - #ifdef HAVE_TLS enum lload_tls_type c_is_tls; /* true if this LDAP over raw TLS */ #endif diff --git a/servers/lloadd/tier_bestof.c b/servers/lloadd/tier_bestof.c index ef96dd3a15..393258053e 100644 --- a/servers/lloadd/tier_bestof.c +++ b/servers/lloadd/tier_bestof.c @@ -134,21 +134,6 @@ bestof_backend_options( LloadTier *tier, LloadBackend *b, char *arg ) return 1; } -static int -connection_collect_stats( LloadConnection *c, void *arg ) -{ - uintptr_t count, diff, *stats = arg; - - count = __atomic_exchange_n( - &( c )->c_operation_count, 0, __ATOMIC_RELAXED ); - diff = __atomic_exchange_n( &( c )->c_operation_time, 0, __ATOMIC_RELAXED ); - - stats[0] += count; - stats[1] += diff; - - return LDAP_SUCCESS; -} - static int bestof_update( LloadTier *tier ) { @@ -167,25 +152,26 @@ bestof_update( LloadTier *tier ) steps = now - b->b_last_update; if ( b->b_weight && steps > 0 ) { - uintptr_t stats[2] = { 0, 0 }; + uintptr_t count, diff; float factor = 1; - connections_walk( - &b->b_mutex, &b->b_conns, connection_collect_stats, stats ); + count = __atomic_exchange_n( + &b->b_operation_count, 0, __ATOMIC_RELAXED ); + diff = __atomic_exchange_n( + &b->b_operation_time, 0, __ATOMIC_RELAXED ); /* Smear values over time - rolling average */ - if ( stats[0] ) { - float fitness = b->b_weight * stats[1]; + if ( count ) { + float fitness = b->b_weight * diff; /* Stretch factor accordingly favouring the latest value */ if ( steps > 10 ) { factor = 0; /* No recent data */ } else if ( steps > 1 ) { - factor = - 1 / ( pow( ( 1 / (float)factor ) + 1, steps ) - 1 ); + factor = 1 / ( pow( ( 1 / factor ) + 1, steps ) - 1 ); } - b->b_fitness = ( factor * b->b_fitness + fitness / stats[0] ) / + b->b_fitness = ( factor * b->b_fitness + fitness / count ) / ( factor + 1 ); b->b_last_update = now; } diff --git a/servers/lloadd/upstream.c b/servers/lloadd/upstream.c index cd02f4c733..29093c2bfe 100644 --- a/servers/lloadd/upstream.c +++ b/servers/lloadd/upstream.c @@ -254,11 +254,13 @@ handle_one_response( LloadConnection *c ) gettimeofday( &tv, NULL ); if ( !timerisset( &op->o_last_response ) ) { + LloadBackend *b = c->c_backend; + timersub( &tv, &op->o_start, &tvdiff ); diff = 1000000 * tvdiff.tv_sec + tvdiff.tv_usec; - __atomic_add_fetch( &c->c_operation_count, 1, __ATOMIC_RELAXED ); - __atomic_add_fetch( &c->c_operation_time, diff, __ATOMIC_RELAXED ); + __atomic_add_fetch( &b->b_operation_count, 1, __ATOMIC_RELAXED ); + __atomic_add_fetch( &b->b_operation_time, diff, __ATOMIC_RELAXED ); } op->o_last_response = tv;