mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-30 18:39:28 -05:00
ITS#9599 Push based latency tracking
This commit is contained in:
parent
84dab3f961
commit
8219a3a414
3 changed files with 16 additions and 28 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue