]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9599 Push based latency tracking
authorOndřej Kuzník <okuznik@symas.com>
Wed, 10 Mar 2021 16:17:33 +0000 (16:17 +0000)
committerOndřej Kuzník <okuznik@symas.com>
Fri, 13 Aug 2021 09:57:14 +0000 (10:57 +0100)
servers/lloadd/lload.h
servers/lloadd/tier_bestof.c
servers/lloadd/upstream.c

index ec6c9d0c0fd36a9fb9dd45d182232c2bfdf1556c..85b4d6761f08fedeffdf2cd7d0ee522acd9fbad8 100644 (file)
@@ -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
index ef96dd3a15d75b56687102afed56fd4e91d6fa08..393258053ea079a32e604dbb76ab9ce443d39ab1 100644 (file)
@@ -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;
             }
index cd02f4c7333923484924f289230b3f5083ea296d..29093c2bfed62cf18fc86dd6cf37f6575feb2bd9 100644 (file)
@@ -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;