Module: kamailio
Branch: master
Commit: 8429ef380517f321ea05c2c2e2cdbd221712df49
URL:
https://github.com/kamailio/kamailio/commit/8429ef380517f321ea05c2c2e2cdbd2…
Author: Julien Chavanton <jchavanton(a)gmail.com>
Committer: Julien Chavanton <jchavanton(a)gmail.com>
Date: 2020-10-06T13:20:25-07:00
dispatcher: add an attribute to preset the
latency estimator
---
Modified: src/modules/dispatcher/dispatch.c
Modified: src/modules/dispatcher/dispatch.h
Modified: src/modules/dispatcher/doc/dispatcher_admin.xml
---
Diff:
https://github.com/kamailio/kamailio/commit/8429ef380517f321ea05c2c2e2cdbd2…
Patch:
https://github.com/kamailio/kamailio/commit/8429ef380517f321ea05c2c2e2cdbd2…
---
diff --git a/src/modules/dispatcher/dispatch.c b/src/modules/dispatcher/dispatch.c
index 8e798a871b..23b4d16967 100644
--- a/src/modules/dispatcher/dispatch.c
+++ b/src/modules/dispatcher/dispatch.c
@@ -319,6 +319,11 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs)
} else if(pit->name.len == 6
&& strncasecmp(pit->name.s, "weight", 6) == 0) {
str2sint(&pit->body, &dest->attrs.weight);
+ } else if(pit->name.len == 7
+ && strncasecmp(pit->name.s, "latency", 7) == 0) {
+ int initial_latency = 0;
+ if (str2sint(&pit->body, &initial_latency) == 0)
+ latency_stats_init(&dest->latency_stats, initial_latency, 10000);
} else if(pit->name.len == 7
&& strncasecmp(pit->name.s, "maxload", 7) == 0) {
str2sint(&pit->body, &dest->attrs.maxload);
@@ -2587,6 +2592,16 @@ int ds_mark_dst(struct sip_msg *msg, int state)
return (ret == 0) ? 1 : -1;
}
+void latency_stats_init(ds_latency_stats_t *latency_stats, int latency, int count) {
+ latency_stats->stdev = 0.0f;
+ latency_stats->m2 = 0.0f;
+ latency_stats->max = latency;
+ latency_stats->min = latency;
+ latency_stats->average = latency;
+ latency_stats->estimate = latency;
+ latency_stats->count = count;
+}
+
static inline void latency_stats_update(ds_latency_stats_t *latency_stats, int latency)
{
int training_count = 10000;
@@ -2596,18 +2611,14 @@ static inline void latency_stats_update(ds_latency_stats_t
*latency_stats, int l
} else { /* We adjust the sum of squares used by the oneline algorithm proportionally
*/
latency_stats->m2 -= latency_stats->m2/latency_stats->count;
}
- if (latency_stats->count == 1) {
- latency_stats->stdev = 0.0f;
- latency_stats->m2 = 0.0f;
- latency_stats->max = latency;
- latency_stats->min = latency;
- latency_stats->average = latency;
- latency_stats->estimate = latency;
- }
+
+ if (latency_stats->count == 1)
+ latency_stats_init(latency_stats, latency, 1);
/* stabilize-train the estimator if the average is stable after 10 samples */
if (latency_stats->count > 10 && latency_stats->count <
training_count
&& latency_stats->stdev < 0.5)
latency_stats->count = training_count;
+
if (latency_stats->min > latency)
latency_stats->min = latency;
if (latency_stats->max < latency)
diff --git a/src/modules/dispatcher/dispatch.h b/src/modules/dispatcher/dispatch.h
index 2bd63dc64b..dada7ed5d8 100644
--- a/src/modules/dispatcher/dispatch.h
+++ b/src/modules/dispatcher/dispatch.h
@@ -204,6 +204,8 @@ typedef struct _ds_latency_stats {
uint32_t timeout;
} ds_latency_stats_t;
+void latency_stats_init(ds_latency_stats_t *latency_stats, int latency, int count);
+
typedef struct _ds_dest {
str uri; /*!< address/uri */
int flags; /*!< flags */
diff --git a/src/modules/dispatcher/doc/dispatcher_admin.xml
b/src/modules/dispatcher/doc/dispatcher_admin.xml
index 0b9b4495b0..d4ed3261ec 100644
--- a/src/modules/dispatcher/doc/dispatcher_admin.xml
+++ b/src/modules/dispatcher/doc/dispatcher_admin.xml
@@ -709,6 +709,7 @@ modparam("dispatcher", "ds_probing_mode", 1)
<title><varname>ds_ping_latency_stats</varname> (int)</title>
<para>
Enable latency measurement when pinging nodes
+ The estimator can be initialized at startup and reload using the attribute latency.
</para>
<itemizedlist>
@@ -735,6 +736,9 @@ DEST: {
URI: sip:1.2.3.4
FLAGS: AX
PRIORITY: 9
+ ATTRS: {
+ BODY: latency=24
+ }
LATENCY: {
AVG: 24.250000 # weighted moving average for the last few weeks
STD: 1.035000 # standard deviation of AVG
@@ -2126,6 +2130,9 @@ kamctl rpc dispatcher.hash 4 bob
server.com
<para>'obproxy' - SIP URI of outbound proxy to be used when sending
pings. It overwrites the general ds_outbound_proxy parameter.</para>
</listitem>
+ <listitem>
+ <para>'latency' - latency_stats initialization in ms.</para>
+ </listitem>
</itemizedlist>
</para>
</section>