Hello.
I’m wondering how the “Weight” column in the LCR ‘gw’ table Works.
I have 5 gateways defined with different weights.
gw_name grp_id ip_addr hostname port uri_scheme transport strip tag weight ping flags
GW02 58 10.0.0.71 5060 1 1 4 0258 10 0 0
GW03 58 10.0.0.72 5060 1 1 4 0258 10 0 0
GW05 58 10.0.0.132 5060 1 1 4 0258 20 0 0
GW06 58 10.0.0.133 5060 1 1 4 0258 20 0 0
GW09 58 10.0.0.70 5060 1 1 4 0258 20 0 0
GW10 58 10.0.0.69 5060 1 1 4 0258 20 0 0
If I have 100 calls, I was expecting was to have 20 to GW05, 20 to GW06, 20 to GW09 and 20 to GW10
Finalle 10 to GW02 and 10 to GW02.
Is this the correct interpretation of this parameter?
Thanks in advance.
Regards,
Ricardo Martinez.-
2010/9/22 Ricardo Martinez rmartinez@redvoiss.net:
If I have 100 calls, I was expecting was to have 20 to GW05, 20 to GW06, 20 to GW09 and 20 to GW10
Finalle 10 to GW02 and 10 to GW02.
Is this the correct interpretation of this parameter?
Yes, but note you need to do much more that 100 calls in order the got statistics to match.
Ricardo Martinez writes:
I’m wondering how the “Weight” column in the LCR ‘gw’ table Works.
weight is probabilistic weight of the gateway that applies when priorities of the gateways are the same.
If I have 100 calls, I was expecting was to have 20 to GW05, 20 to GW06, 20 to GW09 and 20 to GW10
Finalle 10 to GW02 and 10 to GW02.
Is this the correct interpretation of this parameter?
you don't get exactly those numbers. what did you observe?
-- juha
Hello Juha.
I’m observing something like this : (these are “Simmultaneous calls” graphs)
As you can see the GW05, Gw06, Gw09 and GW10 seems to share the load equally, as expected.. but I was also expecting a little more load in the GW02 ad Gw03.
They seems to me very underloaded (according to the LCR weight column).
Is this normal?...
What can you see from the graphs?
Thanks in advance,
Regards,
Ricardo.-
-----Mensaje original----- De: sr-users-bounces@lists.sip-router.org [mailto: sr-users-bounces@lists.sip-router.org] En nombre de Juha Heinanen Enviado el: jueves, 23 de septiembre de 2010 11:17 Para: Ricardo Martinez CC: users@lists.kamailio.org Asunto: [SR-Users] LCR "weight" column question
Ricardo Martinez writes:
I’m wondering how the “Weight” column in the LCR ‘gw’ table Works.
weight is probabilistic weight of the gateway that applies when
priorities of the gateways are the same.
If I have 100 calls, I was expecting was to have 20 to GW05, 20 to GW06,
20
to GW09 and 20 to GW10
Finalle 10 to GW02 and 10 to GW02.
Is this the correct interpretation of this parameter?
you don't get exactly those numbers. what did you observe?
-- juha
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Ricardo Martinez writes:
I’m observing something like this : (these are “Simmultaneous calls” graphs)
ricardo,
my email client does not know to display your data, but weight is assigned to gws like this:
matched_gws[gw_index].weight = t->weight * (rand() >> 8);
where t->weight comes from db table. then the gws are sorted based on prefix length, priority and the above weight value.
-- juha
Hello Juha. I'm attaching the graphics in JPG versión. Also I have the logs from the LCR. The logs reveals the same behavior after 24 hours of operation.
Device Calls % GW02 520 1,04 GW0 502 1,01 GW05 12148 24,44 GW06 12276 24,70 GW09 12174 24,49 GW10 12074 24,29
Total 49694
As you can see there is no a 20,20,20,20,10,10 call repartition. Could this be a bug?
Hope you can help me. Regards, Ricardo.-
-----Mensaje original----- De: sr-users-bounces@lists.sip-router.org [mailto:sr-users-bounces@lists.sip-router.org] En nombre de Juha Heinanen Enviado el: jueves, 23 de septiembre de 2010 14:53 Para: Ricardo Martinez CC: users@lists.kamailio.org Asunto: Re: [SR-Users] LCR "weight" column question
Ricardo Martinez writes:
I’m observing something like this : (these are “Simmultaneous calls” graphs)
ricardo,
my email client does not know to display your data, but weight is assigned to gws like this:
matched_gws[gw_index].weight = t->weight * (rand() >> 8);
where t->weight comes from db table. then the gws are sorted based on prefix length, priority and the above weight value.
-- juha
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Ricardo Martinez writes:
As you can see there is no a 20,20,20,20,10,10 call repartition. Could this be a bug?
ricardo,
it is a "feature" of the way randomized weights are currently calculated. if you have two wgs with weights 1 and 2 and then generate two random numbers
1 * random number 2 * random number
then the probability that the latter result is less than 10 is 50 %, but that it also is less than the first number is only 25 %.
i searched around a bit and didn't find any fast way to calculate a better weighted random number. the algorithms i found where based on an idea of creating an array of gws where each gw appears in the array as many times as its weight is and then a random number is generated between [1, size of the array] and a gw in that random number index of the array is selected.
any ideas on how to improve weighted random number calculation without loosing performance?
-- juha
ricardo,
i studied the weight problem a bit more and came to the conclusion that implementing a fair weighting algorithm would be too complicated.
below is a script that can be used to find weight values matching desired probabilities for lcr gateways. i don't know if it would be appropriate to include it in utils or scripts directory.
-- juha
#!/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"; }
?>
Hello Juha. Thanks for your help. The script works fine. We made a test using the values "20 20 20 20 10 10" and it gave us the exact values that I calculated for the actual gateways.
Device Calls % GW02 520 1,04 GW03 502 1,01 GW05 12148 24,44 GW06 12276 24,70 GW09 12174 24,49 GW10 12074 24,29
Total 49694
So, we created another "weight" values and gave us the percentage we were looking for.
18 18 18 18 16 16
That gaves us 20% 20% 20% 20% 10% and 10%.
So, we think it should be very useful if you can include this script in the "utils", and maybe give more information in the REDME file of LCR about the weight "column", until now we believe this column represents the percentage of each gateway.
Thanks again,
Regards, Ricardo.-
-----Mensaje original----- De: Juha Heinanen [mailto:jh@tutpro.com] Enviado el: domingo, 26 de septiembre de 2010 2:03 Para: Ricardo Martinez; users@lists.kamailio.org Asunto: Re: [SR-Users] LCR "weight" column question
ricardo,
i studied the weight problem a bit more and came to the conclusion that implementing a fair weighting algorithm would be too complicated.
below is a script that can be used to find weight values matching desired probabilities for lcr gateways. i don't know if it would be appropriate to include it in utils or scripts directory.
-- juha
#!/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"; }
?>
Hello,
On 9/24/10 9:43 AM, Juha Heinanen wrote:
[...] any ideas on how to improve weighted random number calculation without loosing performance?
maybe there are other options, but here is what I did for dispatcher weighted load balancing: - each destination set has associated an array of 100 integers - when destination set is loaded, this array is filled with indexes of destination addresses in the set as many times as associated weight value - when this array is filled, the content is randomized
At runtime, a position of the last used index in array is keep, incremented and looped again over the array. During the load the 100-indexes array is traversed 2 times, once to fill and second to radomize, but then selection is very fast at runtime, which is more important for a load balancer, since loading is done very rarely and in MI/RPC process, in parallel with normal operation using old data.
Code is in modules_k/dispacher/dispatch.c, function dp_init_weights().
Cheers, Daniel
Daniel-Constantin Mierla writes:
maybe there are other options, but here is what I did for dispatcher weighted load balancing:
- each destination set has associated an array of 100 integers
- when destination set is loaded, this array is filled with indexes of
destination addresses in the set as many times as associated weight value
- when this array is filled, the content is randomized
daniel,
this is the same algorithm that i was looking at to implement only that i was thinking to use an array that was long enough to hold the sum of the weights.
At runtime, a position of the last used index in array is keep, incremented and looped again over the array. During the load the 100-indexes array is traversed 2 times, once to fill and second to radomize, but then selection is very fast at runtime, which is more important for a load balancer, since loading is done very rarely and in MI/RPC process, in parallel with normal operation using old data.
in case of lcr, things are more complicated, because in the set of matching gateways for a destination, gws are ordered first based on prefix length, then based on priority and finally based on randomized weight. so there should be several of those arrays. also, the arrays would need to be created and organized every time load_gws() is called, i.e., once per call. this would result in lots of code lines and performance hit at load_gws() call.
the script that i wrote can be used to figure out the desired weights without any implementation complexity. just a single rand() call for each matching gw and a single qsort() call for the set is all that is needed. so, for now, i'll include the script in the tools dir and reference it in lcr README.
-- juha
On 9/27/10 7:44 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
maybe there are other options, but here is what I did for dispatcher weighted load balancing:
- each destination set has associated an array of 100 integers
- when destination set is loaded, this array is filled with indexes of
destination addresses in the set as many times as associated weight value
- when this array is filled, the content is randomized
daniel,
this is the same algorithm that i was looking at to implement only that i was thinking to use an array that was long enough to hold the sum of the weights.
At runtime, a position of the last used index in array is keep, incremented and looped again over the array. During the load the 100-indexes array is traversed 2 times, once to fill and second to radomize, but then selection is very fast at runtime, which is more important for a load balancer, since loading is done very rarely and in MI/RPC process, in parallel with normal operation using old data.
in case of lcr, things are more complicated, because in the set of matching gateways for a destination, gws are ordered first based on prefix length, then based on priority and finally based on randomized weight. so there should be several of those arrays. also, the arrays would need to be created and organized every time load_gws() is called, i.e., once per call. this would result in lots of code lines and performance hit at load_gws() call.
the script that i wrote can be used to figure out the desired weights without any implementation complexity. just a single rand() call for each matching gw and a single qsort() call for the set is all that is needed. so, for now, i'll include the script in the tools dir and reference it in lcr README.
you can create as well an utils or tools directory inside lcr module folder, that will suggest direct relation with the module.
Cheers, Daniel
If the script can be provided in bash, then it would be nice to be integrated in kamctl: - kamctl lcr weight_eval <weight_1> <weight_2> ... <weight_n>
Regards, Ovidiu Sas
On Mon, Sep 27, 2010 at 1:53 PM, Juha Heinanen jh@tutpro.com wrote:
Daniel-Constantin Mierla writes:
you can create as well an utils or tools directory inside lcr module folder, that will suggest direct relation with the module.
ok, juha
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
just to mention that kamctl base depends on awk, so this language can be used in case something is easier to do with it than pure shell.
Cheers, Daniel
On 9/28/10 8:53 PM, Juha Heinanen wrote:
Ovidiu Sas writes:
If the script can be provided in bash, then it would be nice to be integrated in kamctl:
- kamctl lcr weight_eval<weight_1> <weight_2> ...<weight_n>
ovidiu,
possibly it could be done, but i'm not that good in bash.
-- juha
Daniel-Constantin Mierla writes:
just to mention that kamctl base depends on awk, so this language can be used in case something is easier to do with it than pure shell.
i created awk version of lcr_weight_test script. i'm not using kamctl myself, but if someone is and would like to call this script from kamctl, he/she should now be able to add that command to kamctl.
-- juha
Hello Juha,
The awk version of the script is now integrated in kamctl.
Regards, Ovidiu Sas
On Wed, Sep 29, 2010 at 6:59 AM, Juha Heinanen jh@tutpro.com wrote:
Daniel-Constantin Mierla writes:
just to mention that kamctl base depends on awk, so this language can be used in case something is easier to do with it than pure shell.
i created awk version of lcr_weight_test script. i'm not using kamctl myself, but if someone is and would like to call this script from kamctl, he/she should now be able to add that command to kamctl.
-- juha