furmur created an issue (kamailio/kamailio#4331)

have a question about EWMA formula in the dispatcher module.

documentation for ds_latency_estimator_alpha points to this explanation
which specifies EWMA formula as: $EWMA_t = \lambda*Y_t + (1 - \lambda) * EWMA_{t-1}$

related code at src/modules/dispatcher/dispatch.c:

static inline void latency_stats_update(
		ds_latency_stats_t *latency_stats, int latency)
{
...
    /* exponentially weighted moving average */
    if(latency_stats->count < 10) {
        latency_stats->estimate = latency_stats->average;
    } else {
        latency_stats->estimate =
                latency_stats->estimate * ds_latency_estimator_alpha
                + latency * (1 - ds_latency_estimator_alpha);
    }

so:

looks like latency_stats->estimate and latency are swapped regarding to the formula and as a result higher ds_latency_estimator_alpha will rate old average over the actual latency value and that contradicts both dispatcher module documentation and meaning in the referenced formula.

i believe that code should be:

        latency_stats->estimate =
                latency * ds_latency_estimator_alpha
                + latency_stats->estimate * (1 - ds_latency_estimator_alpha);

could someone verify those observations? will make PR if i am not mistaken.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/issues/4331@github.com>