metered scheduling executor adapter
Summary: Motivation: we sometimes need to add concept of lower priorities on top of executors which provide custom scheduling via custom APIs such `EDFThreadPoolExecutor`. This adapter wraps an arbitrary executor, and adds an additional queue. Tasks from this queue will be fetched and placed on the wrapped executor's queue in a metered fashion - in particular we only allow up to "maxReadAtOnce" tasks to be placed onto the main executors queue. Once work is added to metered queue, the adapter schedules callback into the wrapped executor. When callback is executed it: 1) fetches head task from the queue 2) fetches up to maxReadAtOnce - 1, and reschedules those onto the main executor. 3) reschedules itself onto the main executor 4) executes the task fetched at stage 1. While in theory this algorithm does not provide strong priority guarantees, in practice lower priority tasks are almost always yielding to the higher priority tasks. This primitive also allows interesting compositions to be built: 1. multiple priorities scheduling can be achieved by chaining metered adapters. 2. Fair queue scheduling (e.g. round robin consumption from N queues) can be achieved by creating N metered adapters wrapping the same executor. (Note: this ignores all push blocking failures!) Reviewed By: prshreshtha Differential Revision: D24983861 fbshipit-source-id: 1a4ce61fc7cc706889da9724de71822bfaab440b
Showing
Please register or sign in to comment