[SR-Users] LCR "weight" column question

Ricardo Martinez rmartinez at redvoiss.net
Mon Sep 27 18:42:04 CEST 2010


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 at tutpro.com]
Enviado el: domingo, 26 de septiembre de 2010 2:03
Para: Ricardo Martinez; users at 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";
 }

?>



More information about the sr-users mailing list