[SR-Users] LCR "weight" column question
Daniel-Constantin Mierla
miconda at gmail.com
Mon Sep 27 19:28:45 CEST 2010
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
http://www.asipto.com
More information about the sr-users
mailing list