MB-18453: Make task scheduling fairer 29/65929/3
authorJim Walker <jim@couchbase.com>
Thu, 30 Jun 2016 10:23:20 +0000 (11:23 +0100)
committerDave Rigby <daver@couchbase.com>
Wed, 20 Jul 2016 12:54:36 +0000 (12:54 +0000)
commit0009ef75606381c9a69059668b132e0f9b65fadf
treeef235dce4cd3aeda73f2878df08f10a2e25194c1
parent723739eccc55537a25dfa32eb3f85f2aea729463
MB-18453: Make task scheduling fairer

The MB identified that we can starve tasks by scheduling
a higher priority task via ExecutorPool::wake().

This occurs because ExecutorPool::wake() pushes tasks
into the readyQueue enabling frequent wakes to trigger
the starvation bug.

The fix is to remove readyQueue.push from wake, so that we only
push to the readyQueue. The fetch side of scheduling only looks at
the futureQueue once the readyQueue is empty, thus the identified
starvation won't happen.

A unit-test demonstrates the fix using the single-threaded harness and
expects that two tasks of differing priorities get executed, rather
than the wake() starving the low-priority task.

This test drives:
 - ExecutorPool::schedule
 - ExecutorPool::reschedule
 - ExecutorPool::wake

These are all the methods which can add tasks into the scheduler
queue.

The fetch side is also covered:
 - ExecutorPool::fetchNextTask

This commit is an update to a previous commit that was reverted due
to performance issues. The original commit was reverted to minimise
disruption.

- original commit is e22c9ebeda1aac
- revert is 27cb1120e3e37

Change-Id: I70a4dcf7cd1c3a6f04548e9bbc3f95e24cdf50ad
Reviewed-on: http://review.couchbase.org/65929
Well-Formed: buildbot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/executorpool.h
src/fakes/fake_executorpool.h
src/taskqueue.cc
tests/module_tests/evp_store_single_threaded_test.cc