Commit 8219a3a4 authored by Ondřej Kuzník's avatar Ondřej Kuzník
Browse files

ITS#9599 Push based latency tracking

parent 84dab3f9
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment