MINOR: tasks: only visit filled task slots after processing them

process_runnable_tasks() needs to requeue or wake up tasks after
processing them in batches. By only refilling the existing ones, we
avoid revisiting all the queue. The performance gain is measurable
starting with two threads, where the request rate climbs to 657k/s
compared to 644k.
This commit is contained in:
Willy Tarreau 2017-11-06 08:36:53 +01:00
parent 88ac59be4d
commit 9d4b56b88e

View File

@ -188,6 +188,7 @@ void process_runnable_tasks()
struct eb32sc_node *rq_next; struct eb32sc_node *rq_next;
struct task *local_tasks[16]; struct task *local_tasks[16];
int local_tasks_count; int local_tasks_count;
int final_tasks_count;
tasks_run_queue_cur = tasks_run_queue; /* keep a copy for reporting */ tasks_run_queue_cur = tasks_run_queue; /* keep a copy for reporting */
nb_tasks_cur = nb_tasks; nb_tasks_cur = nb_tasks;
max_processed = tasks_run_queue; max_processed = tasks_run_queue;
@ -241,6 +242,7 @@ void process_runnable_tasks()
SPIN_UNLOCK(TASK_RQ_LOCK, &rq_lock); SPIN_UNLOCK(TASK_RQ_LOCK, &rq_lock);
final_tasks_count = 0;
for (i = 0; i < local_tasks_count ; i++) { for (i = 0; i < local_tasks_count ; i++) {
t = local_tasks[i]; t = local_tasks[i];
/* This is an optimisation to help the processor's branch /* This is an optimisation to help the processor's branch
@ -250,13 +252,13 @@ void process_runnable_tasks()
t = process_stream(t); t = process_stream(t);
else else
t = t->process(t); t = t->process(t);
local_tasks[i] = t; if (t)
local_tasks[final_tasks_count++] = t;
} }
SPIN_LOCK(TASK_RQ_LOCK, &rq_lock); SPIN_LOCK(TASK_RQ_LOCK, &rq_lock);
for (i = 0; i < local_tasks_count ; i++) { for (i = 0; i < final_tasks_count ; i++) {
t = local_tasks[i]; t = local_tasks[i];
if (likely(t != NULL)) {
t->state &= ~TASK_RUNNING; t->state &= ~TASK_RUNNING;
/* If there is a pending state /* If there is a pending state
* we have to wake up the task * we have to wake up the task
@ -268,7 +270,6 @@ void process_runnable_tasks()
else else
task_queue(t); task_queue(t);
} }
}
} while (max_processed > 0); } while (max_processed > 0);
SPIN_UNLOCK(TASK_RQ_LOCK, &rq_lock); SPIN_UNLOCK(TASK_RQ_LOCK, &rq_lock);