<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10590">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip.c: Make taskprocessor scheduling algorithm pick the shortest queue<br><br>The current round-robin method does not take the current taskprocessor<br>load into consideration when distributing requests.  Using the least-size<br>method the request goes to the taskprocessor that is servicing the least<br>number of active tasks at the current time.<br><br>Longer running tasks with the round-robin method can delay processing<br>tasks.<br><br>* Change the algorithm from round-robin to least-size for picking the<br>PJSIP taskprocessor from the default serializer pool.<br><br>Change-Id: I7b8d8cc2c2490494f579374b6af0a4868e3a37cd<br>---<br>M res/res_pjsip.c<br>1 file changed, 11 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 3391fee..58645b6 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -2803,9 +2803,6 @@</span><br><span> /*! Number of serializers in pool if one not supplied. */</span><br><span> #define SERIALIZER_POOL_SIZE             8</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! Next serializer pool index to use. */</span><br><span style="color: hsl(0, 100%, 40%);">-static int serializer_pool_pos;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /*! Pool of serializers to use if not supplied. */</span><br><span> static struct ast_taskprocessor *serializer_pool[SERIALIZER_POOL_SIZE];</span><br><span> </span><br><span>@@ -4634,22 +4631,20 @@</span><br><span> </span><br><span> static struct ast_taskprocessor *serializer_pool_pick(void)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    struct ast_taskprocessor *serializer;</span><br><span style="color: hsl(120, 100%, 40%);">+ int idx;</span><br><span style="color: hsl(120, 100%, 40%);">+      int pos = 0;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        unsigned int pos;</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!serializer_pool[0]) {</span><br><span style="color: hsl(120, 100%, 40%);">+            return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /*</span><br><span style="color: hsl(0, 100%, 40%);">-       * Pick a serializer to use from the pool.</span><br><span style="color: hsl(0, 100%, 40%);">-       *</span><br><span style="color: hsl(0, 100%, 40%);">-       * Note: We don't care about any reentrancy behavior</span><br><span style="color: hsl(0, 100%, 40%);">-         * when incrementing serializer_pool_pos.  If it gets</span><br><span style="color: hsl(0, 100%, 40%);">-    * incorrectly incremented it doesn't matter.</span><br><span style="color: hsl(0, 100%, 40%);">-        */</span><br><span style="color: hsl(0, 100%, 40%);">-     pos = serializer_pool_pos++;</span><br><span style="color: hsl(0, 100%, 40%);">-    pos %= SERIALIZER_POOL_SIZE;</span><br><span style="color: hsl(0, 100%, 40%);">-    serializer = serializer_pool[pos];</span><br><span style="color: hsl(120, 100%, 40%);">+    for (idx = 1; idx < SERIALIZER_POOL_SIZE; ++idx) {</span><br><span style="color: hsl(120, 100%, 40%);">+         if (ast_taskprocessor_size(serializer_pool[idx]) < ast_taskprocessor_size(serializer_pool[pos])) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 pos = idx;</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   return serializer;</span><br><span style="color: hsl(120, 100%, 40%);">+    return serializer_pool[pos];</span><br><span> }</span><br><span> </span><br><span> int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10590">change 10590</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10590"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I7b8d8cc2c2490494f579374b6af0a4868e3a37cd </div>
<div style="display:none"> Gerrit-Change-Number: 10590 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>