<p></p>
<h3>Description</h3>
<p>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)</p>
<h3>Expected behavior</h3>
<p>The load to the failed destination to be (hopefully) evenly distributed over the remaining destinations.</p>
<h4>Actual observed behavior</h4>
<p>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</p>
<h4>Debugging Data</h4>
<p>In this test, 6000 Calls were sent to a group of six destinations, using algorithm "0" (hash over Call-ID)</p>
<table role="table">
<thead>
<tr>
<th> </th>
<th>All destinations active</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dest1</td>
<td>996</td>
</tr>
<tr>
<td>Dest2</td>
<td>997</td>
</tr>
<tr>
<td>Dest3</td>
<td>999</td>
</tr>
<tr>
<td>Dest4</td>
<td>1006</td>
</tr>
<tr>
<td>Dest5</td>
<td>1005</td>
</tr>
<tr>
<td>Dest6</td>
<td>997</td>
</tr>
<tr>
<td>Total</td>
<td>6000</td>
</tr>
</tbody>
</table>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/20492105/84825429-6719a580-afef-11ea-971c-d59152fc6550.png"><img src="https://user-images.githubusercontent.com/20492105/84825429-6719a580-afef-11ea-971c-d59152fc6550.png" alt="all_active" style="max-width:100%;"></a></p>
<p>Repeating the test, but with destination Dest4 down:</p>
<table role="table">
<thead>
<tr>
<th> </th>
<th>OriginalImplementation</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dest1</td>
<td>975</td>
</tr>
<tr>
<td>Dest2</td>
<td>993</td>
</tr>
<tr>
<td>Dest3</td>
<td>2022</td>
</tr>
<tr>
<td>Dest4</td>
<td>0</td>
</tr>
<tr>
<td>Dest5</td>
<td>1019</td>
</tr>
<tr>
<td>Dest6</td>
<td>991</td>
</tr>
<tr>
<td>Total</td>
<td>6000</td>
</tr>
</tbody>
</table>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/20492105/84826132-8107b800-aff0-11ea-9663-f6e8992ed5e2.png"><img src="https://user-images.githubusercontent.com/20492105/84826132-8107b800-aff0-11ea-9663-f6e8992ed5e2.png" alt="one_down_original" style="max-width:100%;"></a></p>
<p>We can see that poor destination Dest3 receives double traffic</p>
<h3>Possible Solutions</h3>
<p>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)</p>
<table role="table">
<thead>
<tr>
<th> </th>
<th>New Implementation</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dest1</td>
<td>1175</td>
</tr>
<tr>
<td>Dest2</td>
<td>1206</td>
</tr>
<tr>
<td>Dest3</td>
<td>1191</td>
</tr>
<tr>
<td>Dest4</td>
<td>0</td>
</tr>
<tr>
<td>Dest5</td>
<td>1216</td>
</tr>
<tr>
<td>Dest6</td>
<td>1212</td>
</tr>
<tr>
<td>Total</td>
<td>6000</td>
</tr>
</tbody>
</table>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/20492105/84826051-62092600-aff0-11ea-8f89-f06102e732d5.png"><img src="https://user-images.githubusercontent.com/20492105/84826051-62092600-aff0-11ea-8f89-f06102e732d5.png" alt="one_down_new" style="max-width:100%;"></a></p>
<p>Basically, the solution is as simple as to execute a rehash of the original hash.</p>
<p>I will create a pull request with the proposed change, which I already tested, as it can be seen on the previous chart.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong></li>
</ul>
<pre><code> kamailio 5.4.0-dev4 (x86_64/linux) 0c29e8-dirty
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>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

</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2361">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZJRVRGXDDV6LADB2JDRW7LLDANCNFSM4N77CJNA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZILSBNF6MSLDBBAIDTRW7LLDA5CNFSM4N77CJNKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4JRFCHPA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2361",
"url": "https://github.com/kamailio/kamailio/issues/2361",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>