... | ... |
@@ -319,6 +319,11 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs) |
319 | 319 |
} else if(pit->name.len == 6 |
320 | 320 |
&& strncasecmp(pit->name.s, "weight", 6) == 0) { |
321 | 321 |
str2sint(&pit->body, &dest->attrs.weight); |
322 |
+ } else if(pit->name.len == 7 |
|
323 |
+ && strncasecmp(pit->name.s, "latency", 7) == 0) { |
|
324 |
+ int initial_latency = 0; |
|
325 |
+ if (str2sint(&pit->body, &initial_latency) == 0) |
|
326 |
+ latency_stats_init(&dest->latency_stats, initial_latency, 10000); |
|
322 | 327 |
} else if(pit->name.len == 7 |
323 | 328 |
&& strncasecmp(pit->name.s, "maxload", 7) == 0) { |
324 | 329 |
str2sint(&pit->body, &dest->attrs.maxload); |
... | ... |
@@ -2573,6 +2578,16 @@ int ds_mark_dst(struct sip_msg *msg, int state) |
2573 | 2578 |
return (ret == 0) ? 1 : -1; |
2574 | 2579 |
} |
2575 | 2580 |
|
2581 |
+void latency_stats_init(ds_latency_stats_t *latency_stats, int latency, int count) { |
|
2582 |
+ latency_stats->stdev = 0.0f; |
|
2583 |
+ latency_stats->m2 = 0.0f; |
|
2584 |
+ latency_stats->max = latency; |
|
2585 |
+ latency_stats->min = latency; |
|
2586 |
+ latency_stats->average = latency; |
|
2587 |
+ latency_stats->estimate = latency; |
|
2588 |
+ latency_stats->count = count; |
|
2589 |
+} |
|
2590 |
+ |
|
2576 | 2591 |
static inline void latency_stats_update(ds_latency_stats_t *latency_stats, int latency) { |
2577 | 2592 |
int training_count = 10000; |
2578 | 2593 |
|
... | ... |
@@ -2582,16 +2597,14 @@ static inline void latency_stats_update(ds_latency_stats_t *latency_stats, int l |
2582 | 2597 |
} else { /* We adjust the sum of squares used by the oneline algorithm proportionally */ |
2583 | 2598 |
latency_stats->m2 -= latency_stats->m2/latency_stats->count; |
2584 | 2599 |
} |
2585 |
- if (latency_stats->count == 1) { |
|
2586 |
- latency_stats->stdev = 0.0f; |
|
2587 |
- latency_stats->m2 = 0.0f; |
|
2588 |
- latency_stats->max = latency; |
|
2589 |
- latency_stats->min = latency; |
|
2590 |
- latency_stats->average = latency; |
|
2591 |
- latency_stats->estimate = latency; |
|
2592 |
- } |
|
2593 |
- /* train the average if stable after 10 samples */ |
|
2594 |
- if (latency_stats->count > 10 && latency_stats->stdev < 0.5) latency_stats->count = 500000; |
|
2600 |
+ |
|
2601 |
+ if (latency_stats->count == 1) |
|
2602 |
+ latency_stats_init(latency_stats, latency, 1); |
|
2603 |
+ /* stabilize-train the estimator if the average is stable after 10 samples */ |
|
2604 |
+ if (latency_stats->count > 10 && latency_stats->count < training_count |
|
2605 |
+ && latency_stats->stdev < 0.5) |
|
2606 |
+ latency_stats->count = training_count; |
|
2607 |
+ |
|
2595 | 2608 |
if (latency_stats->min > latency) |
2596 | 2609 |
latency_stats->min = latency; |
2597 | 2610 |
if (latency_stats->max < latency) |
... | ... |
@@ -204,6 +204,8 @@ typedef struct _ds_latency_stats { |
204 | 204 |
uint32_t timeout; |
205 | 205 |
} ds_latency_stats_t; |
206 | 206 |
|
207 |
+void latency_stats_init(ds_latency_stats_t *latency_stats, int latency, int count); |
|
208 |
+ |
|
207 | 209 |
typedef struct _ds_dest { |
208 | 210 |
str uri; /*!< address/uri */ |
209 | 211 |
int flags; /*!< flags */ |
... | ... |
@@ -709,6 +709,7 @@ modparam("dispatcher", "ds_probing_mode", 1) |
709 | 709 |
<title><varname>ds_ping_latency_stats</varname> (int)</title> |
710 | 710 |
<para> |
711 | 711 |
Enable latency measurement when pinging nodes |
712 |
+ The estimator can be initialized at startup and reload using the attribute latency. |
|
712 | 713 |
</para> |
713 | 714 |
|
714 | 715 |
<itemizedlist> |
... | ... |
@@ -735,6 +736,9 @@ DEST: { |
735 | 736 |
URI: sip:1.2.3.4 |
736 | 737 |
FLAGS: AX |
737 | 738 |
PRIORITY: 9 |
739 |
+ ATTRS: { |
|
740 |
+ BODY: latency=24 |
|
741 |
+ } |
|
738 | 742 |
LATENCY: { |
739 | 743 |
AVG: 24.250000 # weighted moving average for the last few weeks |
740 | 744 |
STD: 1.035000 # standard deviation of AVG |
... | ... |
@@ -2126,6 +2130,9 @@ kamctl rpc dispatcher.hash 4 bob server.com |
2126 | 2130 |
<para>'obproxy' - SIP URI of outbound proxy to be used when sending |
2127 | 2131 |
pings. It overwrites the general ds_outbound_proxy parameter.</para> |
2128 | 2132 |
</listitem> |
2133 |
+ <listitem> |
|
2134 |
+ <para>'latency' - latency_stats initialization in ms.</para> |
|
2135 |
+ </listitem> |
|
2129 | 2136 |
</itemizedlist> |
2130 | 2137 |
</para> |
2131 | 2138 |
</section> |