### Description
<!--
I integrate a Kamailio and asterisk with together(Kamailio fo registrar server) as a sip trunk and I have a kazoo server that doesn't send a register message to Kamailio and I want to register this kazoo manually to my Kamailio location and asterisk sipregs with fixed values and send an incoming call to kazoo from another hosted PBXs.
-->
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
```
version: kamailio 5.0.8 (x86_64/linux)
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 6.3.0
```
* **Operating System**:
<!--
Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...;
Kernel details (output of `uname -a`)
-->
```
Linux trunk2-sbc 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2378
### Description
Selected algorithm is a hash, over Call-ID, From, etc. If destination is not available, a new one must be selected, without breaking the hash assignation (all messages with the same hash must be forwarded to the same destination)
### Expected behavior
The load to the failed destination to be (hopefully) evenly distributed over the remaining destinations.
#### Actual observed behavior
All the messages that were supposed to be sent to the failed destination are sent to only one of the remaining, causing it to receive double load, comparing with the rest
#### Debugging Data
In this test, 6000 Calls were sent to a group of six destinations, using algorithm "0" (hash over Call-ID)
| All destinations active
-- | --
Dest1 | 996
Dest2 | 997
Dest3 | 999
Dest4 | 1006
Dest5 | 1005
Dest6 | 997
Total | 6000

Repeating the test, but with destination Dest4 down:
| OriginalImplementation
-- | --
Dest1 | 975
Dest2 | 993
Dest3 | 2022
Dest4 | 0
Dest5 | 1019
Dest6 | 991
Total | 6000

We can see that poor destination Dest3 receives double traffic
### Possible Solutions
I implemented a solution that does not break the expected behavior (messages with same hash are assigned the same destination, but with a better distribution over remaining destinations)
| New Implementation
-- | --
Dest1 | 1175
Dest2 | 1206
Dest3 | 1191
Dest4 | 0
Dest5 | 1216
Dest6 | 1212
Total | 6000

Basically, the solution is as simple as to execute a rehash of the original hash.
I will create a pull request with the proposed change, which I already tested, as it can be seen on the previous chart.
### Additional Information
* **Kamailio Version**
```
kamailio 5.4.0-dev4 (x86_64/linux) 0c29e8-dirty
```
* **Operating System**:
```
Linux Rechitsa 5.4.19-100.fc30.x86_64 #1 SMP Tue Feb 11 22:27:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2361