<p>i believe that one(or a few) malloc's is better than continuous locking.</p>
<p>in theory we also could soften (add a rounding) by a some (configurable) <em>factor</em> to <code>it_l <=> load</code> equation to slightly move from load-based distribution to (pseudo-)equal-rate distribution (with<code>rand()</code>)</p>
<p>So what do you think about this commit?</p>
<p>P.S.<br>
we also could use a trick to do something like this:</p>
<div class="highlight highlight-cpp"><pre><span class="pl-s">static</span> <span class="pl-st">struct</span> <span class="pl-en">lb_dst</span> **dsts;
<span class="pl-st">struct</span> <span class="pl-en">lb_dst</span> **dsts_cur;
<span class="pl-st">struct</span> <span class="pl-en">lb_dst</span> *dsts_tmp;
<span class="pl-k">if</span> ( (flags & LB_FLAGS_RANDOM) && (data->dst_no > <span class="pl-c1">1</span>) ) {
<span class="pl-c">/* allocate space with pkg_realloc() in dsts */</span>
dsts_cur = dsts;
} <span class="pl-k">else</span> {
dsts_cur = &dsts_tmp;
dsts_size_cur = <span class="pl-c1">1</span>;
}</pre></div>
<p>so no malloc's happen when LB_FLAGS_RANDOM flag unset.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/pull/345#issuecomment-72465761">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AFOciT4NvWe2gGCDw3LyUiHnHOWdWFe9ks5nn4EqgaJpZM4CpiN1.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/OpenSIPS/opensips/pull/345#issuecomment-72465761"></link>
<meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>