Scaling with Dask
This guide demonstrates how you can offload tasks to Dask to scale your apps to bigger datasets, bigger calculations and more users.
Panel supports async
and await
. This means you can easily offload large computations to your Dask cluster asynchronously and keep your app responsive while you await
the results. Please note that off loading the computations to the Dask cluster can add ~250msec of overhead and thus is not suitable for all kinds of use cases.
Installation
Lets start by installing Panel, hvPlot and Dask Distributed.
Start the Cluster
For development, testing and many use cases a LocalCluster
is more than fine and will allow you to leverage all the CPUs on your machine. When you want to scale out to an entire cluster will you can switch to a non-local cluster. To avoid any issues when combining Panel and Dask we recommend starting the LocalCluster
separately from the Dask Client
and your Panel app.
and running
You can now open the Dask Dashboard at http://localhost:8787/status.
So far there is not a lot to see here:
The Dask Client
will serialize any tasks and send them to the Dask Cluster
for execution. This means that the Client
and Cluster
must able to import the same versions of all tasks and python package dependencies.
Dask Distributed
Fibonacci Task Queue
In this section we will define a Panel app to submit and monitor Fibonacci tasks.
Let's start by defining the fibonacci tasks in a tasks.py
file:
Lets now define the full app.py
file.
You can now run panel serve app.py
and the app will look like
Dask Dashboard Components
It can be very useful to include some of the live Dask endpoints in your app. Its easy to do by embedding the specific urls in an iframe.
In the dashboard.py
file we define the DaskViewer
component that can be used to explore the individual dask plots.
Try running panel serve dashboard.py
. If your Dask cluster is working, you will see something like