furmur created an issue (kamailio/kamailio#4331)
have a question about EWMA formula in the `dispatcher` module.
[documentation](https://www.kamailio.org/docs/modules/devel/modules/dispatcher.html#dispatcher.p.ds_latency_estimator_alpha)
for `ds_latency_estimator_alpha` points to this
[explanation](https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc324.htm)
which specifies EWMA formula as: $EWMA_t = \lambda*Y_t + (1 - \lambda) *
EWMA_{t-1}$
related code at
[`src/modules/dispatcher/dispatch.c`](https://github.com/kamailio/kamailio/blob/master/src/modules/dispatcher/dispatch.c#L3191):
```
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:
* `latency_stats->estimate` is $EWMA$,
* `ds_latency_estimator_alpha` is $\lambda\$.
* `latency` is $Y_t$
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 or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4331
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/issues/4...@github.com>
_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the
sender!