Module: kamailio Branch: master Commit: a2b52c52e8a2503c53825b82fb66d7af11b9bc4e URL: https://github.com/kamailio/kamailio/commit/a2b52c52e8a2503c53825b82fb66d7af11b9bc4e
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2014-12-15T12:37:42+01:00 dispatcher: proper filling of weights array when summ is less than 100 - more comments on building the array for weight based distribution --- Modified: modules/dispatcher/dispatch.c --- Diff: https://github.com/kamailio/kamailio/commit/a2b52c52e8a2503c53825b82fb66d7af11b9bc4e.diff Patch: https://github.com/kamailio/kamailio/commit/a2b52c52e8a2503c53825b82fb66d7af11b9bc4e.patch --- diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index e8da58b..434593a 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -416,7 +416,10 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs, } /** - * + * Initialize the weight distribution for a destination set + * - build an array of 0..99 where to keep the index of the + * destination address to be used. The Nth call will use + * the address with the index at possition N%100 */ int dp_init_weights(ds_set_t *dset) { @@ -431,6 +434,11 @@ int dp_init_weights(ds_set_t *dset) if(dset->dlist[0].attrs.weight==0) return 0; + /* first fill the array based on the weight of each destination + * - the weight is the percentage (e.g., if weight=20, the afferent + * address gets its index 20 times in the array) + * - if the sum of weights is more than 100, the addresses over the + * limit are ignored */ t = 0; for(j=0; j<dset->nr; j++) { @@ -442,10 +450,15 @@ int dp_init_weights(ds_set_t *dset) t++; } } - j = (t-1>=0)?t-1:0; + /* if the array was not completely filled (i.e., the sum of weights is + * less than 100), then use last address to fill the rest */ for(; t<100; t++) - dset->wlist[t] = (unsigned int)j; + dset->wlist[t] = (unsigned int)(dset->nr-1); randomize: + /* shuffle the content of the array in order to mix the selection + * of the addresses (e.g., if first address has weight=20, avoid + * sending first 20 calls to it, but ensure that within a 100 calls, + * 20 go to first address */ srand(time(0)); for (j=0; j<100; j++) { _______________________________________________ sr-dev mailing list [email protected] http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
