Browse code

Merge ef167712bd7fbe4ea0419b647bb5f2abf1af53dd into 60f04b6d6f51b55294d22722df3f351a76cbfb9b

Julien Chavanton authored on 28/09/2020 20:00:19 • GitHub committed on 28/09/2020 20:00:19
Showing 1 changed files
... ...
@@ -2588,6 +2588,8 @@ int ds_mark_dst(struct sip_msg *msg, int state)
2588 2588
 }
2589 2589
 
2590 2590
 static inline void latency_stats_update(ds_latency_stats_t *latency_stats, int latency) {
2591
+	int training_count = 10000;
2592
+
2591 2593
 	/* after 2^21 ~24 days at 1s interval, the average becomes a weighted average */
2592 2594
 	if (latency_stats->count < 2097152) {
2593 2595
 		latency_stats->count++;
... ...
@@ -2602,8 +2604,10 @@ static inline void latency_stats_update(ds_latency_stats_t *latency_stats, int l
2602 2604
 		latency_stats->average = latency;
2603 2605
 		latency_stats->estimate = latency;
2604 2606
 	}
2605
-	/* train the average if stable after 10 samples */
2606
-	if (latency_stats->count > 10 && latency_stats->stdev < 0.5) latency_stats->count = 500000;
2607
+	/* stabilize-train the estimator if the average is stable after 10 samples */
2608
+	if (latency_stats->count > 10 && latency_stats->count < training_count
2609
+	        && latency_stats->stdev < 0.5)
2610
+		latency_stats->count = training_count;
2607 2611
 	if (latency_stats->min > latency)
2608 2612
 		latency_stats->min = latency;
2609 2613
 	if (latency_stats->max < latency)