[Spce-user] Value wight, how it works?
Daniel Grotti
dgrotti at sipwise.com
Wed Jan 21 08:15:58 EST 2015
Hi Mykola,
take in mind that weights are just a probabilitythat one peer will be
selected or not.
Higher weight has higher probability.
With the following script:
lcr_weight_test.php
#!/usr/bin/php
<?php
// This script can be used to find out actual probabilities
// that correspond to a list of LCR gateway weights.
if ($argc < 2) {
echo "Usage: lcr_weight_test.php <list of weights (integers 1-254)>\n";
exit;
}
$iters = 10000;
$rands = array();
for ($i = 1; $i <= $iters; $i++) {
$elem = array();
for ($j = 1; $j < $argc; $j++) {
$elem["$j"] = $argv[$j] * (rand() >> 8);
}
$rands[] = $elem;
}
$sorted = array();
foreach ($rands as $rand) {
asort($rand);
$sorted[] = $rand;
}
$counts = array();
for ($j = 1; $j < $argc; $j++) {
$counts["$j"] = 0;
}
foreach ($sorted as $rand) {
end($rand);
$counts[key($rand)]++;
}
for ($j = 1; $j < $argc; $j++) {
echo "weight " . $argv[$j] . " probability " . $counts["$j"]/$iters .
"\n";
}
?>
you can check the probability that a peer with weight 1 and one with
weight 2 are selected, with:
./lcr_weight_test.php 1 2
output:
weight 1 probability 0.2522
weight 2 probability 0.7478
as you can see, peer with weight 2 has 74% of probability to be
selected, peer with weight 1 25%.
Daniel
On 01/21/2015 02:10 PM, Mykola Zaika wrote:
> Hi,
> I have a problem with my routing.
>
> example:
> I created one group "Test".
> This group include two peers:
> peer1 (IP x.x.x.x) port 5060 wight 1
> peer2 (IP y.y.y.y) port 5060 wight 2
> Also there are created peering rules
>
> I try to change value "wight", but it does not work. Calls are always
> going randomly via peers. One time via peer1, next time via peer2. I
> do not understand why.
>
>
> From manual:
>
> The selection of peering servers for outbound calls is done in the
> following order: 1. length of the matching peering
> rules for a call. 2. priority of the peering group.*3. weight of the
> peering servers in the selected peering group*. After one
> or more peering group(s) is matched for an outbound call, all servers
> in this group are tried, according to their weight
> (lower weight has more precedence). If a peering server replies with
> SIP codes 408 , 500 or 503 , or if a peering
> server doesn’t respond at all, the next peering server in the current
> peering group is used as a fallback, one after the
> other until the call succeeds. If no more servers are left in the
> current peering group, the next group which matches the
> peering rules is going to be used.
>
>
> A bit from log:
> Jan 21 13:46:47 spce /usr/sbin/kamailio[16077]: INFO: <script>: Load
> gws matching calling part 'sip:032255 at 10.110.10.55
> <mailto:sip%3A032255 at 10.110.10.55>' and called user 'peerB_032255' and
> called part 'sip:peerB_032255 at 10.110.10.55
> <mailto:sip%3ApeerB_032255 at 10.110.10.55>' - R=sip:peerB_03225
> 5 at 10.110.10.55 <mailto:5 at 10.110.10.55>
> ID=5fc804c63f7f89564addaac057f3d894 at 10.110.10.55
> <mailto:5fc804c63f7f89564addaac057f3d894 at 10.110.10.55>
> Jan 21 13:46:47 spce /usr/sbin/kamailio[16077]: INFO: <script>: Dialog
> set mark type to outgoing - R=sip:peerB_032255 at 10.110.10.55
> <mailto:sip%3ApeerB_032255 at 10.110.10.55>
> ID=5fc804c63f7f89564addaac057f3d894 at 10.110.10.55
> <mailto:5fc804c63f7f89564addaac057f3d894 at 10.110.10.55>
> Jan 21 13:46:47 spce /usr/sbin/kamailio[16077]: INFO: <script>: Load
> peer preferences for peer host '11' -
> R=sip:peerB_032255 at 10.110.10.12:5060;transport=udp
> ID=5fc804c63f7f89564addaac057f3d894 at 10.110.10.55
> <mailto:5fc804c63f7f89564addaac057f3d894 at 10.110.10.55>
> Jan 21 13:46:47 spce /usr/sbin/kamailio[16077]: INFO: <script>: Load
> dialplan IDs for peer host '11' -
> R=sip:peerB_032255 at 10.110.10.12:5060;transport=udp
> ID=5fc804c63f7f89564addaac057f3d894 at 10.110.10.55
> <mailto:5fc804c63f7f89564addaac057f3d894 at 10.110.10.55>
>
> --
> З повагою,
> Микола Заїка
> Компанія VoIPTime,
> Тел: +380 32 2328022 <tel:%2B380%2032%202328022>
> mzaika at voiptime.net <mailto:ydidukh at voiptime.net>
> www.voiptime.net <http://www.voiptime.net>
>
>
> _______________________________________________
> Spce-user mailing list
> Spce-user at lists.sipwise.com
> https://lists.sipwise.com/listinfo/spce-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sipwise.com/pipermail/spce-user_lists.sipwise.com/attachments/20150121/e5f93baa/attachment-0001.html>
More information about the Spce-user
mailing list