| 1 |
Configuration |
| 2 |
============= |
| 3 |
|
| 4 |
Taking full advantage of Dask sometimes requires user configuration. |
| 5 |
This might be to control logging verbosity, specify cluster configuration, |
| 6 |
provide credentials for security, or any of several other options that arise in |
| 7 |
production. |
| 8 |
|
| 9 |
Configuration is specified in one of the following ways: |
| 10 |
|
| 11 |
1. YAML files in ``~/.config/dask/`` or ``/etc/dask/`` |
| 12 |
2. Environment variables like ``DASK_DISTRIBUTED__SCHEDULER__WORK_STEALING=True`` |
| 13 |
3. Default settings within sub-libraries |
| 14 |
|
| 15 |
This combination makes it easy to specify configuration in a variety of |
| 16 |
settings ranging from personal workstations, to IT-mandated configuration, to |
| 17 |
docker images. |
| 18 |
|
| 19 |
|
| 20 |
Access Configuration |
| 21 |
-------------------- |
| 22 |
|
| 23 |
.. currentmodule:: dask |
| 24 |
|
| 25 |
.. autosummary:: |
| 26 |
dask.config.get |
| 27 |
|
| 28 |
Dask's configuration system is usually accessed using the ``dask.config.get`` function. |
| 29 |
You can use ``.`` for nested access, for example: |
| 30 |
|
| 31 |
.. code-block:: python |
| 32 |
|
| 33 |
>>> import dask |
| 34 |
>>> import dask.distributed # populate config with distributed defaults |
| 35 |
|
| 36 |
>>> dask.config.get("distributed.client") # use `.` for nested access |
| 37 |
{'heartbeat': '5s', 'scheduler-info-interval': '2s'} |
| 38 |
|
| 39 |
>>> dask.config.get("distributed.scheduler.unknown-task-duration") |
| 40 |
'500ms' |
| 41 |
|
| 42 |
You may wish to inspect the ``dask.config.config`` dictionary to get a sense |
| 43 |
for what configuration is being used by your current system. |
| 44 |
|
| 45 |
Note that the ``get`` function treats underscores and hyphens identically. |
| 46 |
For example, ``dask.config.get("temporary-directory")`` is equivalent to |
| 47 |
``dask.config.get("temporary_directory")``. |
| 48 |
|
| 49 |
Values like ``"128 MiB"`` and ``"10s"`` are parsed using the functions in |
| 50 |
:ref:`api.utilities`. |
| 51 |
|
| 52 |
Specify Configuration |
| 53 |
--------------------- |
| 54 |
|
| 55 |
YAML files |
| 56 |
~~~~~~~~~~ |
| 57 |
|
| 58 |
You can specify configuration values in YAML files. For example: |
| 59 |
|
| 60 |
.. code-block:: yaml |
| 61 |
|
| 62 |
array: |
| 63 |
chunk-size: 128 MiB |
| 64 |
|
| 65 |
distributed: |
| 66 |
worker: |
| 67 |
memory: |
| 68 |
spill: 0.85 # default: 0.7 |
| 69 |
target: 0.75 # default: 0.6 |
| 70 |
terminate: 0.98 # default: 0.95 |
| 71 |
|
| 72 |
dashboard: |
| 73 |
# Locate the dashboard if working on a Jupyter Hub server |
| 74 |
link: /user/<user>/proxy/8787/status |
| 75 |
|
| 76 |
|
| 77 |
These files can live in any of the following locations: |
| 78 |
|
| 79 |
1. The ``~/.config/dask`` directory in the user's home directory |
| 80 |
2. The ``{sys.prefix}/etc/dask`` directory local to Python |
| 81 |
3. The ``{prefix}/etc/dask`` directories with ``{prefix}`` in `site.PREFIXES |
| 82 |
<https://docs.python.org/3/library/site.html#site.PREFIXES>`_ |
| 83 |
4. The root directory (specified by the ``DASK_ROOT_CONFIG`` environment |
| 84 |
variable or ``/etc/dask/`` by default) |
| 85 |
|
| 86 |
Dask searches for *all* YAML files within each of these directories and merges |
| 87 |
them together, preferring configuration files closer to the user over system |
| 88 |
configuration files (preference follows the order in the list above). |
| 89 |
Additionally, users can specify a path with the ``DASK_CONFIG`` environment |
| 90 |
variable, which takes precedence at the top of the list above. |
| 91 |
|
| 92 |
The contents of these YAML files are merged together, allowing different |
| 93 |
Dask subprojects like ``dask-kubernetes`` or ``dask-ml`` to manage configuration |
| 94 |
files separately, but have them merge into the same global configuration. |
| 95 |
|
| 96 |
|
| 97 |
Environment Variables |
| 98 |
~~~~~~~~~~~~~~~~~~~~~ |
| 99 |
|
| 100 |
You can also specify configuration values with environment variables like |
| 101 |
the following: |
| 102 |
|
| 103 |
.. code-block:: bash |
| 104 |
|
| 105 |
export DASK_DISTRIBUTED__SCHEDULER__WORK_STEALING=True |
| 106 |
export DASK_DISTRIBUTED__SCHEDULER__ALLOWED_FAILURES=5 |
| 107 |
export DASK_DISTRIBUTED__DASHBOARD__LINK="/user/<user>/proxy/8787/status" |
| 108 |
|
| 109 |
resulting in configuration values like the following: |
| 110 |
|
| 111 |
.. code-block:: python |
| 112 |
|
| 113 |
{ |
| 114 |
'distributed': { |
| 115 |
'scheduler': { |
| 116 |
'work-stealing': True, |
| 117 |
'allowed-failures': 5 |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
Dask searches for all environment variables that start with ``DASK_``, then |
| 123 |
transforms keys by converting to lower case and changing double-underscores to |
| 124 |
nested structures. |
| 125 |
|
| 126 |
Dask tries to parse all values with `ast.literal_eval |
| 127 |
<https://docs.python.org/3/library/ast.html#ast.literal_eval>`_, letting users |
| 128 |
pass numeric and boolean values (such as ``True`` in the example above) as well |
| 129 |
as lists, dictionaries, and so on with normal Python syntax. |
| 130 |
|
| 131 |
Environment variables take precedence over configuration values found in YAML |
| 132 |
files. |
| 133 |
|
| 134 |
Defaults |
| 135 |
~~~~~~~~ |
| 136 |
|
| 137 |
Additionally, individual subprojects may add their own default values when they |
| 138 |
are imported. These are always added with lower priority than the YAML files |
| 139 |
or environment variables mentioned above: |
| 140 |
|
| 141 |
.. code-block:: python |
| 142 |
|
| 143 |
>>> import dask.config |
| 144 |
>>> dask.config.config # no configuration by default |
| 145 |
{} |
| 146 |
|
| 147 |
>>> import dask.distributed |
| 148 |
>>> dask.config.config # New values have been added |
| 149 |
{ |
| 150 |
'scheduler': ..., |
| 151 |
'worker': ..., |
| 152 |
'tls': ... |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
Directly within Python |
| 157 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 158 |
|
| 159 |
.. autosummary:: |
| 160 |
dask.config.set |
| 161 |
|
| 162 |
Configuration is stored within a normal Python dictionary in |
| 163 |
``dask.config.config`` and can be modified using normal Python operations. |
| 164 |
|
| 165 |
Additionally, you can temporarily set a configuration value using the |
| 166 |
``dask.config.set`` function. This function accepts a dictionary as an input |
| 167 |
and interprets ``"."`` as nested access: |
| 168 |
|
| 169 |
.. code-block:: python |
| 170 |
|
| 171 |
>>> dask.config.set({'optimization.fuse.ave-width': 4}) |
| 172 |
|
| 173 |
This function can also be used as a context manager for consistent cleanup: |
| 174 |
|
| 175 |
.. code-block:: python |
| 176 |
|
| 177 |
>>> with dask.config.set({'optimization.fuse.ave-width': 4}): |
| 178 |
... arr2, = dask.optimize(arr) |
| 179 |
|
| 180 |
Note that the ``set`` function treats underscores and hyphens identically. |
| 181 |
For example, ``dask.config.set({'optimization.fuse.ave_width': 4})`` is |
| 182 |
equivalent to ``dask.config.set({'optimization.fuse.ave-width': 4})``. |
| 183 |
|
| 184 |
Finally, note that persistent objects may acquire configuration settings when |
| 185 |
they are initialized. These settings may also be cached for performance reasons. |
| 186 |
This is particularly true for ``dask.distributed`` objects such as Client, Scheduler, |
| 187 |
Worker, and Nanny. |
| 188 |
|
| 189 |
Directly from CLI |
| 190 |
~~~~~~~~~~~~~~~~~ |
| 191 |
|
| 192 |
Configuration can also be set and viewed from the CLI. |
| 193 |
|
| 194 |
.. code-block:: |
| 195 |
|
| 196 |
$ dask config set optimization.fuse.ave-width 4 |
| 197 |
Updated [optimization.fuse.ave-width] to [4], config saved to ~/dask/dask.yaml |
| 198 |
|
| 199 |
$ dask config get optimization.fuse.ave-width |
| 200 |
4 |
| 201 |
|
| 202 |
|
| 203 |
Distributing configuration |
| 204 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 205 |
|
| 206 |
It may also be desirable to package up your whole Dask configuration for use on |
| 207 |
another machine. This is used in some Dask Distributed libraries to ensure remote components |
| 208 |
have the same configuration as your local system. |
| 209 |
|
| 210 |
This is typically handled by the downstream libraries which use base64 encoding to pass |
| 211 |
config via the ``DASK_INTERNAL_INHERIT_CONFIG`` environment variable. |
| 212 |
|
| 213 |
.. autosummary:: |
| 214 |
dask.config.serialize |
| 215 |
dask.config.deserialize |
| 216 |
|
| 217 |
Conversion Utility |
| 218 |
~~~~~~~~~~~~~~~~~~ |
| 219 |
|
| 220 |
It is possible to configure Dask inline with dot notation, with YAML or via environment variables. You can enter |
| 221 |
your own configuration items below to convert back and forth. |
| 222 |
|
| 223 |
.. warning:: |
| 224 |
This utility is designed to improve understanding of converting between different notations |
| 225 |
and does not claim to be a perfect implementation. Please use for reference only. |
| 226 |
|
| 227 |
**YAML** |
| 228 |
|
| 229 |
.. raw:: html |
| 230 |
|
| 231 |
<textarea id="configConvertUtilYAML" name="configConvertUtilYAML" rows="10" cols="50" class="configTextArea" wrap="off"> |
| 232 |
array: |
| 233 |
chunk-size: 128 MiB |
| 234 |
|
| 235 |
distributed: |
| 236 |
workers: |
| 237 |
memory: |
| 238 |
spill: 0.85 |
| 239 |
target: 0.75 |
| 240 |
terminate: 0.98 |
| 241 |
</textarea> |
| 242 |
|
| 243 |
**Environment variable** |
| 244 |
|
| 245 |
.. raw:: html |
| 246 |
|
| 247 |
<textarea id="configConvertUtilEnv" name="configConvertUtilEnv" rows="10" cols="50" class="configTextArea" wrap="off"> |
| 248 |
export DASK_ARRAY__CHUNK_SIZE="128 MiB" |
| 249 |
export DASK_DISTRIBUTED__WORKERS__MEMORY__SPILL=0.85 |
| 250 |
export DASK_DISTRIBUTED__WORKERS__MEMORY__TARGET=0.75 |
| 251 |
export DASK_DISTRIBUTED__WORKERS__MEMORY__TERMINATE=0.98 |
| 252 |
</textarea> |
| 253 |
|
| 254 |
**Inline with dot notation** |
| 255 |
|
| 256 |
.. raw:: html |
| 257 |
|
| 258 |
<textarea id="configConvertUtilCode" name="configConvertUtilCode" rows="10" cols="50" class="configTextArea" wrap="off"> |
| 259 |
>>> dask.config.set({"array.chunk-size": "128 MiB"}) |
| 260 |
>>> dask.config.set({"distributed.workers.memory.spill": 0.85}) |
| 261 |
>>> dask.config.set({"distributed.workers.memory.target": 0.75}) |
| 262 |
>>> dask.config.set({"distributed.workers.memory.terminate": 0.98}) |
| 263 |
</textarea> |
| 264 |
|
| 265 |
Updating Configuration |
| 266 |
---------------------- |
| 267 |
|
| 268 |
Manipulating configuration dictionaries |
| 269 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 270 |
|
| 271 |
.. autosummary:: |
| 272 |
dask.config.merge |
| 273 |
dask.config.update |
| 274 |
dask.config.expand_environment_variables |
| 275 |
|
| 276 |
As described above, configuration can come from many places, including several |
| 277 |
YAML files, environment variables, and project defaults. Each of these |
| 278 |
provides a configuration that is possibly nested like the following: |
| 279 |
|
| 280 |
.. code-block:: python |
| 281 |
|
| 282 |
x = {'a': 0, 'c': {'d': 4}} |
| 283 |
y = {'a': 1, 'b': 2, 'c': {'e': 5}} |
| 284 |
|
| 285 |
Dask will merge these configurations respecting nested data structures, and |
| 286 |
respecting order: |
| 287 |
|
| 288 |
.. code-block:: python |
| 289 |
|
| 290 |
>>> dask.config.merge(x, y) |
| 291 |
{'a': 1, 'b': 2, 'c': {'d': 4, 'e': 5}} |
| 292 |
|
| 293 |
You can also use the ``update`` function to update the existing configuration |
| 294 |
in place with a new configuration. This can be done with priority being given |
| 295 |
to either config. This is often used to update the global configuration in |
| 296 |
``dask.config.config``: |
| 297 |
|
| 298 |
.. code-block:: python |
| 299 |
|
| 300 |
dask.config.update(dask.config, new, priority='new') # Give priority to new values |
| 301 |
dask.config.update(dask.config, new, priority='old') # Give priority to old values |
| 302 |
|
| 303 |
Sometimes it is useful to expand environment variables stored within a |
| 304 |
configuration. This can be done with the ``expand_environment_variables`` |
| 305 |
function: |
| 306 |
|
| 307 |
.. code-block:: python |
| 308 |
|
| 309 |
dask.config.config = dask.config.expand_environment_variables(dask.config.config) |
| 310 |
|
| 311 |
Refreshing Configuration |
| 312 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 313 |
|
| 314 |
.. autosummary:: |
| 315 |
dask.config.collect |
| 316 |
dask.config.refresh |
| 317 |
|
| 318 |
If you change your environment variables or YAML files, Dask will not |
| 319 |
immediately see the changes. Instead, you can call ``refresh`` to go through |
| 320 |
the configuration collection process and update the default configuration: |
| 321 |
|
| 322 |
.. code-block:: python |
| 323 |
|
| 324 |
>>> dask.config.config |
| 325 |
{} |
| 326 |
|
| 327 |
>>> # make some changes to yaml files |
| 328 |
|
| 329 |
>>> dask.config.refresh() |
| 330 |
>>> dask.config.config |
| 331 |
{...} |
| 332 |
|
| 333 |
This function uses ``dask.config.collect``, which returns the configuration |
| 334 |
without modifying the global configuration. You might use this to determine |
| 335 |
the configuration of particular paths not yet on the config path: |
| 336 |
|
| 337 |
.. code-block:: python |
| 338 |
|
| 339 |
>>> dask.config.collect(paths=[...]) |
| 340 |
{...} |
| 341 |
|
| 342 |
Downstream Libraries |
| 343 |
-------------------- |
| 344 |
|
| 345 |
.. autosummary:: |
| 346 |
dask.config.ensure_file |
| 347 |
dask.config.update |
| 348 |
dask.config.update_defaults |
| 349 |
|
| 350 |
Downstream Dask libraries often follow a standard convention to use the central |
| 351 |
Dask configuration. This section provides recommendations for integration |
| 352 |
using a fictional project, ``dask-foo``, as an example. |
| 353 |
|
| 354 |
Downstream projects typically follow the following convention: |
| 355 |
|
| 356 |
1. Maintain default configuration in a YAML file within their source |
| 357 |
directory:: |
| 358 |
|
| 359 |
setup.py |
| 360 |
dask_foo/__init__.py |
| 361 |
dask_foo/config.py |
| 362 |
dask_foo/core.py |
| 363 |
dask_foo/foo.yaml # <--- |
| 364 |
|
| 365 |
2. Place configuration in that file within a namespace for the project: |
| 366 |
|
| 367 |
.. code-block:: yaml |
| 368 |
|
| 369 |
# dask_foo/foo.yaml |
| 370 |
|
| 371 |
foo: |
| 372 |
color: red |
| 373 |
admin: |
| 374 |
a: 1 |
| 375 |
b: 2 |
| 376 |
|
| 377 |
3. Within a config.py file (or anywhere) load that default config file and |
| 378 |
update it into the global configuration: |
| 379 |
|
| 380 |
.. code-block:: python |
| 381 |
|
| 382 |
# dask_foo/config.py |
| 383 |
import os |
| 384 |
import yaml |
| 385 |
|
| 386 |
import dask.config |
| 387 |
|
| 388 |
fn = os.path.join(os.path.dirname(__file__), 'foo.yaml') |
| 389 |
|
| 390 |
with open(fn) as f: |
| 391 |
defaults = yaml.safe_load(f) |
| 392 |
|
| 393 |
dask.config.update_defaults(defaults) |
| 394 |
|
| 395 |
4. Ensure that this file is run on import by including it in ``__init__.py``: |
| 396 |
|
| 397 |
.. code-block:: python |
| 398 |
|
| 399 |
# dask_foo/__init__.py |
| 400 |
|
| 401 |
from . import config |
| 402 |
|
| 403 |
5. Within ``dask_foo`` code, use the ``dask.config.get`` function to access |
| 404 |
configuration values: |
| 405 |
|
| 406 |
.. code-block:: python |
| 407 |
|
| 408 |
# dask_foo/core.py |
| 409 |
|
| 410 |
def process(fn, color=dask.config.get('foo.color')): |
| 411 |
... |
| 412 |
|
| 413 |
6. You may also want to ensure that your yaml configuration files are included |
| 414 |
in your package. This can be accomplished by including the following line |
| 415 |
in your MANIFEST.in:: |
| 416 |
|
| 417 |
recursive-include <PACKAGE_NAME> *.yaml |
| 418 |
|
| 419 |
and the following in your setup.py ``setup`` call: |
| 420 |
|
| 421 |
.. code-block:: python |
| 422 |
|
| 423 |
from setuptools import setup |
| 424 |
|
| 425 |
setup(..., |
| 426 |
include_package_data=True, |
| 427 |
...) |
| 428 |
|
| 429 |
This process keeps configuration in a central place, but also keeps it safe |
| 430 |
within namespaces. It places config files in an easy to access location |
| 431 |
by default (``~/.config/dask/\*.yaml``), so that users can easily discover what |
| 432 |
they can change, but maintains the actual defaults within the source code, so |
| 433 |
that they more closely track changes in the library. |
| 434 |
|
| 435 |
However, downstream libraries may choose alternative solutions, such as |
| 436 |
isolating their configuration within their library, rather than using the |
| 437 |
global dask.config system. All functions in the ``dask.config`` module also |
| 438 |
work with parameters, and do not need to mutate global state. |
| 439 |
|
| 440 |
|
| 441 |
API |
| 442 |
--- |
| 443 |
|
| 444 |
.. autofunction:: dask.config.get |
| 445 |
.. autofunction:: dask.config.set |
| 446 |
.. autofunction:: dask.config.merge |
| 447 |
.. autofunction:: dask.config.update |
| 448 |
.. autofunction:: dask.config.collect |
| 449 |
.. autofunction:: dask.config.refresh |
| 450 |
.. autofunction:: dask.config.ensure_file |
| 451 |
.. autofunction:: dask.config.expand_environment_variables |
| 452 |
|
| 453 |
|
| 454 |
Configuration Reference |
| 455 |
----------------------- |
| 456 |
|
| 457 |
.. contents:: :local: |
| 458 |
|
| 459 |
.. note:: |
| 460 |
It is possible to configure Dask inline with dot notation, with YAML or via environment variables. |
| 461 |
See the `conversion utility <#conversion-utility>`_ for converting the following dot notation to other forms. |
| 462 |
|
| 463 |
Dask |
| 464 |
~~~~ |
| 465 |
|
| 466 |
.. dask-config-block:: |
| 467 |
:location: dask |
| •468 |
:config: file:///../debian/dask-config-blocks/dask.yaml |
| 469 |
:schema: file:///../debian/dask-config-blocks/dask-schema.yaml |
| 470 |
|
| 471 |
|
| 472 |
Distributed Client |
| 473 |
~~~~~~~~~~~~~~~~~~ |
| 474 |
|
| 475 |
.. dask-config-block:: |
| 476 |
:location: distributed.client |
| •477 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 478 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 479 |
|
| 480 |
Distributed Comm |
| 481 |
~~~~~~~~~~~~~~~~ |
| 482 |
|
| 483 |
.. dask-config-block:: |
| 484 |
:location: distributed.comm |
| •485 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 486 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 487 |
|
| 488 |
|
| 489 |
Distributed Dashboard |
| 490 |
~~~~~~~~~~~~~~~~~~~~~ |
| 491 |
|
| 492 |
.. dask-config-block:: |
| 493 |
:location: distributed.dashboard |
| •494 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 495 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 496 |
|
| 497 |
|
| 498 |
Distributed Deploy |
| 499 |
~~~~~~~~~~~~~~~~~~ |
| 500 |
|
| 501 |
.. dask-config-block:: |
| 502 |
:location: distributed.deploy |
| •503 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 504 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 505 |
|
| 506 |
|
| 507 |
Distributed Scheduler |
| 508 |
~~~~~~~~~~~~~~~~~~~~~ |
| 509 |
|
| 510 |
.. dask-config-block:: |
| 511 |
:location: distributed.scheduler |
| •512 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 513 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 514 |
|
| 515 |
|
| 516 |
Distributed Worker |
| 517 |
~~~~~~~~~~~~~~~~~~ |
| 518 |
|
| 519 |
.. dask-config-block:: |
| 520 |
:location: distributed.worker |
| •521 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 522 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 523 |
|
| 524 |
|
| 525 |
Distributed Nanny |
| 526 |
~~~~~~~~~~~~~~~~~ |
| 527 |
|
| 528 |
.. dask-config-block:: |
| 529 |
:location: distributed.nanny |
| •530 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 531 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 532 |
|
| 533 |
|
| 534 |
Distributed Admin |
| 535 |
~~~~~~~~~~~~~~~~~ |
| 536 |
|
| 537 |
.. dask-config-block:: |
| 538 |
:location: distributed.admin |
| •539 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 540 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |
| 541 |
|
| 542 |
|
| 543 |
Distributed RMM |
| 544 |
~~~~~~~~~~~~~~~ |
| 545 |
|
| 546 |
.. dask-config-block:: |
| 547 |
:location: distributed.rmm |
| •548 |
:config: file:///../debian/dask-config-blocks/distributed.yaml |
| 549 |
:schema: file:///../debian/dask-config-blocks/distributed-schema.yaml |