[Asterisk-code-review] res pjsip.c: Make taskprocessor scheduling algorithm pick th... (asterisk[16])
Joshua Colp
asteriskteam at digium.com
Mon Nov 12 05:38:37 CST 2018
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10589 )
Change subject: res_pjsip.c: Make taskprocessor scheduling algorithm pick the shortest queue
......................................................................
res_pjsip.c: Make taskprocessor scheduling algorithm pick the shortest queue
The current round-robin method does not take the current taskprocessor
load into consideration when distributing requests. Using the least-size
method the request goes to the taskprocessor that is servicing the least
number of active tasks at the current time.
Longer running tasks with the round-robin method can delay processing
tasks.
* Change the algorithm from round-robin to least-size for picking the
PJSIP taskprocessor from the default serializer pool.
Change-Id: I7b8d8cc2c2490494f579374b6af0a4868e3a37cd
---
M res/res_pjsip.c
1 file changed, 11 insertions(+), 16 deletions(-)
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
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 9eefbcc..494df5c 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2792,9 +2792,6 @@
/*! Number of serializers in pool if one not supplied. */
#define SERIALIZER_POOL_SIZE 8
-/*! Next serializer pool index to use. */
-static int serializer_pool_pos;
-
/*! Pool of serializers to use if not supplied. */
static struct ast_taskprocessor *serializer_pool[SERIALIZER_POOL_SIZE];
@@ -4576,22 +4573,20 @@
static struct ast_taskprocessor *serializer_pool_pick(void)
{
- struct ast_taskprocessor *serializer;
+ int idx;
+ int pos = 0;
- unsigned int pos;
+ if (!serializer_pool[0]) {
+ return NULL;
+ }
- /*
- * Pick a serializer to use from the pool.
- *
- * Note: We don't care about any reentrancy behavior
- * when incrementing serializer_pool_pos. If it gets
- * incorrectly incremented it doesn't matter.
- */
- pos = serializer_pool_pos++;
- pos %= SERIALIZER_POOL_SIZE;
- serializer = serializer_pool[pos];
+ for (idx = 1; idx < SERIALIZER_POOL_SIZE; ++idx) {
+ if (ast_taskprocessor_size(serializer_pool[idx]) < ast_taskprocessor_size(serializer_pool[pos])) {
+ pos = idx;
+ }
+ }
- return serializer;
+ return serializer_pool[pos];
}
int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
--
To view, visit https://gerrit.asterisk.org/10589
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b8d8cc2c2490494f579374b6af0a4868e3a37cd
Gerrit-Change-Number: 10589
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181112/81de7674/attachment-0001.html>
More information about the asterisk-code-review
mailing list