| 1 |
Adaptive deployments |
| 2 |
==================== |
| 3 |
|
| 4 |
Motivation |
| 5 |
---------- |
| 6 |
|
| 7 |
Most Dask deployments are static with a single scheduler and a fixed number of |
| 8 |
workers. This results in predictable behavior, but is wasteful of resources in |
| 9 |
two situations: |
| 10 |
|
| 11 |
1. The user may not be using the cluster, or perhaps they are busy |
| 12 |
interpreting a recent result or plot, and so the workers sit idly, |
| 13 |
taking up valuable shared resources from other potential users |
| 14 |
2. The user may be very active, and is limited by their original allocation. |
| 15 |
|
| 16 |
Particularly efficient users may learn to manually add and remove workers |
| 17 |
during their session, but this is rare. Instead, we would like the size of a |
| 18 |
Dask cluster to match the computational needs at any given time. This is the |
| 19 |
goal of the *adaptive deployments* discussed in this document. |
| 20 |
|
| 21 |
| |
| 22 |
|
| 23 |
.. image:: images/dask-adaptive.svg |
| 24 |
:alt: Dask adaptive scaling |
| 25 |
:align: center |
| 26 |
:scale: 40% |
| 27 |
|
| 28 |
| |
| 29 |
|
| 30 |
These are particularly helpful for interactive workloads, which are characterized by long |
| 31 |
periods of inactivity interrupted with short bursts of heavy activity. |
| 32 |
Adaptive deployments can result in both faster analyses that give users much |
| 33 |
more power, but with much less pressure on computational resources. |
| 34 |
|
| 35 |
.. raw:: html |
| 36 |
|
| 37 |
<iframe width="560" |
| 38 |
height="315" |
| 39 |
src="https://www.youtube.com/embed/dViyEqOMA8U" |
| 40 |
style="margin: 0 auto 20px auto; display: block;" |
| 41 |
frameborder="0" |
| 42 |
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" |
| 43 |
allowfullscreen></iframe> |
| 44 |
|
| 45 |
|
| 46 |
Adaptive |
| 47 |
-------- |
| 48 |
|
| 49 |
To make setting up adaptive deployments easy, some Dask deployment solutions |
| 50 |
offer an ``.adapt()`` method. Here is an example with |
| 51 |
`dask_kubernetes.KubeCluster |
| 52 |
<https://kubernetes.dask.org/en/latest/kubecluster.html>`_. |
| 53 |
|
| 54 |
.. code-block:: python |
| 55 |
|
| 56 |
from dask_kubernetes import KubeCluster |
| 57 |
|
| 58 |
cluster = KubeCluster() |
| 59 |
cluster.adapt(minimum=0, maximum=100) # scale between 0 and 100 workers |
| 60 |
|
| 61 |
For more keyword options, see the Adaptive class below: |
| 62 |
|
| 63 |
.. currentmodule:: distributed.deploy |
| 64 |
|
| 65 |
.. autosummary:: |
| 66 |
Adaptive |
| 67 |
|
| 68 |
|
| 69 |
Dependence on a Resource Manager |
| 70 |
-------------------------------- |
| 71 |
|
| 72 |
The Dask scheduler does not know how to launch workers on its own. Instead, it |
| 73 |
relies on an external resource scheduler like Kubernetes above, or |
| 74 |
Yarn, SGE, SLURM, Mesos, or some other in-house system (see :doc:`how to deploy Dask |
| 75 |
clusters <../deploying>` for options). In order to use adaptive deployments, you |
| 76 |
must provide some mechanism for the scheduler to launch new workers. Typically, |
| 77 |
this is done by using one of the solutions listed in the :doc:`how to deploy Dask |
| 78 |
clusters <../deploying>`, or by subclassing from the Cluster superclass and |
| 79 |
implementing that API. |
| 80 |
|
| 81 |
.. autosummary:: |
| 82 |
Cluster |
| 83 |
|
| 84 |
|
| 85 |
Scaling Heuristics |
| 86 |
------------------ |
| 87 |
|
| 88 |
The Dask scheduler tracks a variety of information that is useful to correctly |
| 89 |
allocate the number of workers: |
| 90 |
|
| 91 |
1. The historical runtime of every function and task that it has seen, |
| 92 |
and all of the functions that it is currently able to run for users |
| 93 |
2. The amount of memory used and available on each worker |
| 94 |
3. Which workers are idle or saturated for various reasons, like the presence |
| 95 |
of specialized hardware |
| 96 |
|
| 97 |
From these, it is able to determine a target number of workers by dividing the |
| 98 |
cumulative expected runtime of all pending tasks by the ``target_duration`` |
| 99 |
parameter (defaults to five seconds). This number of workers serves as a |
| 100 |
baseline request for the resource manager. This number can be altered for a |
| 101 |
variety of reasons: |
| 102 |
|
| 103 |
1. If the cluster needs more memory, then it will choose either the target |
| 104 |
number of workers or twice the current number of workers (whichever is |
| 105 |
larger) |
| 106 |
2. If the target is outside of the range of the minimum and maximum values, |
| 107 |
then it is clipped to fit within that range |
| 108 |
|
| 109 |
Additionally, when scaling down, Dask preferentially chooses those workers that |
| 110 |
are idle and have the least data in memory. It moves that data to other |
| 111 |
machines before retiring the worker. To avoid rapid cycling of the cluster up |
| 112 |
and down in size, we only retire a worker after a few cycles have gone by where |
| 113 |
it has consistently been a good idea to retire it (controlled by the |
| 114 |
``wait_count`` and ``interval`` parameters). |
| 115 |
|
| 116 |
|
| 117 |
API |
| 118 |
--- |
| 119 |
|
| 120 |
.. autoclass:: Adaptive |
| 121 |
.. autoclass:: Cluster |