MB-18453: Make task scheduling fairer 85/65385/7
authorJim Walker <jim@couchbase.com>
Thu, 30 Jun 2016 10:23:20 +0000 (11:23 +0100)
committerDave Rigby <daver@couchbase.com>
Thu, 7 Jul 2016 08:57:23 +0000 (08:57 +0000)
commite22c9ebeda1aac2fc8f4325cc39a93c3bcefffab
tree7a39977225f82849c70153eb39e4aad55db51fb1
parentcae60e343bc0c485cda23f0c349a40831d23a06b
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

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