tigase / tigase-server

(M) Highly optimized, extremely modular and very flexible XMPP/Jabber server
https://tigase.net
GNU Affero General Public License v3.0
326 stars 106 forks source link

Average Processing Time Statistic Calculation #182

Closed karapirinc closed 1 year ago

karapirinc commented 1 year ago

Average processing time calculation does not present actual average time.

tigase.stats.StatisticsInvocationHandler.Statistics#updateExecutionTime

public void updateExecutionTime(long executionTime) {
    executions_counter++;
    avgProcessingTime = (avgProcessingTime + executionTime) / 2;
}

Suppose that, there are 3 executions with 3, 5 and 10ms. Expected average processing time : (3 + 5 + 10) / 3 = 18 / 3 = 6ms Actual average processing time : ( (3 + 5) / 2 + 10 ) / 2 = 7ms

Over time gap between actual and expected times increases. Actual average processing time closer to the last value.

woj-tek commented 1 year ago
I think the confusion stems from the fact, that we are using "moving average" (with very small window). While it may seem "incorrect" in the whole execution period, it gives better indication if there was a spike in the processing time. See the example below: Processing Time (moving) Average processing time (Total) Average processing time
2    
4 3 3
6 5 4
3 4 4
3 3 4
3 3 4
6 5 4
7 6 4
8 7 5
3 5 5
6 5 5
7 6 5
33 20 7
6333 3176 459
6 1591 429
3 797 402
2 400 379
2 201 358
77 139 343
8 73 326
4 39 311
7 23 297
2 12 284
444 228 291
6 117 279
3 60 269
3 32 259
3 17 250
3 10 241
3 7 233