#### Type Of Change - [x] New feature (non-breaking change which adds new functionality)
#### Checklist: - [x] Tested changes locally
#### Description Previously discussed in the mailing list :
**“13” - latency optimized routing mode, the lowest latency gets higher priority (serial forking ordered by priority, ds_ping_latency_stats is required).**
- The algorithm will load balance using round-robin prioritizing the gateways with the highest priority. - The priority will be lowered by 1 point every time the latency ms is as high as the priority.
Using this simple formula : ADJUSTED_PRIORITY = PRIORITY - (ESTIMATED_LATENCY/PRIORITY)
GATEWAY | PRIORITY | ESTIMATED_LATENCY | ADJUSTED_PRIORITY | LOAD DISTRIBUTION -- | -- | -- | -- | -- 1 | 30 | 21 | 30 | 33% 2 | 30 | 91 | 27 | 0% 3 | 30 | 61 | 28 | 0% 4 | 30 | 19 | 30 | 33% 5 | 30 | 32 | 29 | 0% 6 | 30 | 0 | 30 | 33% 7 | 30 | 201 | 24 | 0%
You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2493
-- Commit Summary --
* dispatcher: algorithm 13
-- File Changes --
M src/modules/dispatcher/dispatch.c (43) M src/modules/dispatcher/dispatch.h (1)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2493.patch https://github.com/kamailio/kamailio/pull/2493.diff
@jchavanton pushed 1 commit.
473c42cb6bd83e8a9b3830230b638cda88fe24a8 dispatcher: algorithm 13
- I will make sure the GW are well sorted, not only the first pick. - I am considering additional support for weight based distribution with optional congestion control at equal priority.
@jchavanton pushed 1 commit.
d55861f172ebe14cafd9fac1d5a7b55afa5ea91b dispatcher: algorithm 13
@jchavanton pushed 1 commit.
47a95d0c7761d38ff88ec273681f2bb80c7c0e61 dispatcher: adding doc for algo 13
This pull request **introduces 1 alert** when merging f7c98e2fa2539f01d29335e0dcbed16eeac5c52e into 9935dc8d28a1310084f597fd718af6a21255a799 - [view on LGTM.com](https://lgtm.com/projects/g/kamailio/kamailio/rev/pr-6bd6bec69ce902b41b9e5ab...)
**new alerts:**
* 1 for Comparison result is always the same
This pull request **introduces 1 alert** when merging [f7c98e2](https://github.com/kamailio/kamailio/commit/f7c98e2fa2539f01d29335e0dcbed16e...) into [9935dc8](https://github.com/kamailio/kamailio/commit/9935dc8d28a1310084f597fd718af6a2...) - [view on LGTM.com](https://lgtm.com/projects/g/kamailio/kamailio/rev/pr-6bd6bec69ce902b41b9e5ab...)
**new alerts:**
* 1 for Comparison result is always the same
looked at it, `hash` is returned and can be `-1`
@jchavanton pushed 1 commit.
dbfe2d8310ba009b5ececf2053ea50b7daf91cf5 dispatcher: algorithm 13
This pull request **introduces 1 alert** when merging dbfe2d8310ba009b5ececf2053ea50b7daf91cf5 into e3e6471b114b2358c20cbc9a60ee745ac1bce162 - [view on LGTM.com](https://lgtm.com/projects/g/kamailio/kamailio/rev/pr-ca081d1848726dda18d7eb8...)
**new alerts:**
* 1 for Comparison result is always the same
@jchavanton pushed 1 commit.
46745e567b7606add81d90db93930489b2179b9e dispatcher: algorithm 13
This pull request **introduces 1 alert** when merging 46745e567b7606add81d90db93930489b2179b9e into a1620fa1b4587239835db6ed5765ce04f927172d - [view on LGTM.com](https://lgtm.com/projects/g/kamailio/kamailio/rev/pr-c009862ee0a7fb3c1db1da3...)
**new alerts:**
* 1 for Comparison result is always the same
@jchavanton pushed 1 commit.
5676a0d4f57aa80b3a670ecfb4b0fc53a3b5e532 dispatcher: algorithm 13
This pull request **introduces 1 alert** when merging b793b967753f1ae86b2b4bf2b4ddd064bc45c4c5 into e9624bc4823cfba0bd9536a70b9eeadecb2a537e - [view on LGTM.com](https://lgtm.com/projects/g/kamailio/kamailio/rev/pr-67547820f7133d745f278e3...)
**new alerts:**
* 1 for Comparison result is always the same
@asalman18 commented on this pull request.
z, ds_dest->uri.len, ds_dest->uri.s,
+ gw_priority, latency_proirity_handicap, + ds_dest->attrs.rpriority, gw_latency, ds_dest->flags); + } else { + ds_sorted[y].idx = -1; + ds_sorted[y].priority = -1; + LM_DBG("[inactive]idx[%d]uri[%.*s]priority[%d]latency[%dms]flag[%d]", + z, ds_dest->uri.len, ds_dest->uri.s, + gw_priority, gw_latency, ds_dest->flags); + } + if(ds_use_default != 0 && idx->nr != 1) + z = (z + 1) % (idx->nr - 1); + else + z = (z + 1) % idx->nr; + } + idx->last = hash % idx->nr;
should be removed
@asalman18 commented on this pull request.
@@ -2270,6 +2372,15 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
case DS_ALG_PARALLEL: /* 12 - parallel dispatching */ hash = 0; break; + case DS_ALG_LATENCY: /* 13 - latency optimized round-robin with failover */ + lock_get(&idx->lock); + hash = ds_manage_route_algo13(idx, rstate); + lock_release(&idx->lock); + if (hash < 0)
Should we check if hash is -1 and not < 0
@jchavanton pushed 1 commit.
dfacc805c93a30e5197fccf1cf2b2712a5092e23 dispatcher: algorithm 13
@jchavanton pushed 1 commit.
b2ac69ef7d6531921209221578d7c7a0befe7b85 dispatcher: algorithm 13
load tests at 250CPS
3 gateways, one with excessive ( latency >30ms delta with the 2 others since a priority of 30 is set) ``` URI: sip:147.75.65.247:5072 FLAGS: AP PRIORITY: 30 ATTRS: { BODY: latency=10 } LATENCY: { AVG: 10.039000 STD: 1.381000 EST: 37.871000 MAX: 60 TIMEOUT: 0 }
URI: sip:147.75.65.247:5071 FLAGS: AP PRIORITY: 30 ATTRS: { BODY: latency=250 } LATENCY: { AVG: 249.847000 STD: 5.377000 EST: 141.598000 MAX: 250 TIMEOUT: 0 }
URI: sip:147.75.65.247:5073 FLAGS: AP PRIORITY: 30 LATENCY: { AVG: 59.000000 STD: 0.000000 EST: 59.000000 MAX: 59 TIMEOUT: 0 } ```
algorithm is doing round-robin on GW5072 and GW5073 and keep GW5071 for failover
``` 2(51) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[0]uri[sip:147.75.65.247:5072]priority[30-0=30]latency[10ms]flag[8] 2(51) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[1]uri[sip:147.75.65.247:5071]priority[30-8=22]latency[250ms]flag[8] 2(51) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[2]uri[sip:147.75.65.247:5073]priority[30-0=30]latency[0ms]flag[8] 2(51) INFO: dispatcher [dispatch.c:2224]: ds_manage_route_algo13(): priority[30]gateway_selected[0]next_index[1]
1(50) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[1]uri[sip:147.75.65.247:5071]priority[30-8=22]latency[250ms]flag[8] 1(50) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[2]uri[sip:147.75.65.247:5073]priority[30-0=30]latency[0ms]flag[8] 1(50) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[0]uri[sip:147.75.65.247:5072]priority[30-0=30]latency[10ms]flag[8] 1(50) INFO: dispatcher [dispatch.c:2224]: ds_manage_route_algo13(): priority[30]gateway_selected[2]next_index[0]
5(54) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[0]uri[sip:147.75.65.247:5072]priority[30-0=30]latency[10ms]flag[8] 5(54) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[1]uri[sip:147.75.65.247:5071]priority[30-8=22]latency[250ms]flag[8] 5(54) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[2]uri[sip:147.75.65.247:5073]priority[30-0=30]latency[0ms]flag[8] 5(54) INFO: dispatcher [dispatch.c:2224]: ds_manage_route_algo13(): priority[30]gateway_selected[0]next_index[1]
2(51) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[1]uri[sip:147.75.65.247:5071]priority[30-8=22]latency[250ms]flag[8] 2(51) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[2]uri[sip:147.75.65.247:5073]priority[30-0=30]latency[0ms]flag[8] 2(51) INFO: dispatcher [dispatch.c:2207]: ds_manage_route_algo13(): [active]idx[0]uri[sip:147.75.65.247:5072]priority[30-0=30]latency[10ms]flag[8] 2(51) INFO: dispatcher [dispatch.c:2224]: ds_manage_route_algo13(): priority[30]gateway_selected[2]next_index[0] ```
Thank you for the pull request, and also the announcement on the list. Are there any more additions/refinements done from your side? Otherwise if there are no objections it can be merged, i think.
Merged #2493 into master.