Skip to main content

Run batches with Dask, on Slurm, PBS, SGE, LSF or Kubernetes

With the dask runner, a batch's runs execute on a few long-lived Dask workers, with a bounded concurrency. qa batch starts the workers as jobs of your scheduler: LSF by default, or Slurm, PBS, SGE, HTCondor, OAR, Moab or Kubernetes (see other schedulers). It can also use a Dask cluster you already run. Unlike the LSF runner, where each run is an LSF job, runs don't pay the scheduler's overhead each, and a batch can't flood the cluster.

When to use it
  • Your cluster runs Slurm, PBS, SGE, HTCondor, OAR or Moab.
  • Many short runs (seconds to a few minutes), where the scheduler's overhead dominates.
  • You want to cap how many runs a batch uses at the same time.

On LSF, for long runs or to only cap concurrency, the LSF runner's concurrency option is simpler.

Setup​

Install the optional dependencies:

pip install "qaboard[dask]"
uv add "qaboard[dask]" # or, in a uv project

For workers on Kubernetes, install qaboard[dask-kubernetes] instead. Workers run qa run commands: they must use the same python environment as qa batch, and see the same filesystem, at the same paths. Then check your setup, and start a worker that runs id; hostname:

qa doctor --runner dask --test-job

Configuration​

On LSF, the default:

qaboard.yaml
runners:
default: dask
lsf:
queue: your_queue # used by default for the worker jobs (also: project, resources, max_memory, options)
dask:
concurrency: 20 # max runs in flight for a `qa batch` (default: 10)
cluster: # arguments for dask_jobqueue.LSFCluster, they override the defaults
cores: 4 # runs per worker job, each run is a thread in the worker (default: 1)
memory: 32GB # per worker job: it must cover `cores` runs (default: runners.lsf.max_memory, or 4GB)
# walltime: "24:00" # by default the queue decides
# interface: ib0 # if workers can't reach the scheduler's default address
driver: # for --no-wait: LSF options of the job that runs the scheduler (default: runners.lsf)
queue: some_cpu_queue # it needs little: 1 CPU, it sleeps most of the time
max_memory: 2000 # MB
# resources: "select[...]"
# no_worker_timeout: 600 # give up if all workers are gone for that long (seconds)
# worker_start_timeout: 0 # give up if no worker started after that long (seconds, 0: wait forever)
# scheduler_address: tcp://my-host:8786 # use an existing cluster, see below

You can also choose the runner and concurrency on the CLI:

qa batch --runner dask --dask-concurrency 8 my-batch

A batch can have its own concurrency under dask:, e.g. for runs that need a lot of memory: at most that many of its runs are in flight. Its runs share the workers with the other batches' runs, and qa batch keeps at most the largest concurrency in flight, and starts workers for that many. The command line option wins.

Other schedulers​

cluster.type chooses where qa batch starts the workers. The other settings under cluster are given to the cluster's class, so they are the options of its scheduler:

cluster.typeWorkers areSettings
lsf (default)LSF jobsLSFCluster, with defaults from runners.lsf
slurmSlurm jobsSLURMCluster
pbsPBS jobsPBSCluster
sgeSGE jobsSGECluster
htcondorHTCondor jobsHTCondorCluster
oarOAR jobsOARCluster
moabMoab jobsMoabCluster
kubernetesPods, with the Dask Kubernetes operatorKubeCluster; the image, namespace, resources and user default to runners.kubernetes
localProcesses on the machine that runs qa batchLocalCluster, for big machines and tests

On Slurm, with 4 runs per worker job:

qaboard.yaml
runners:
default: dask
dask:
concurrency: 20
cluster:
type: slurm
queue: <your-partition>
account: <your-account>
cores: 4 # runs per worker job
memory: 64GB # per worker job: for its 4 runs
walltime: "08:00:00"

<your-partition> and <your-account> are your Slurm partition and account (sinfo and sacctmgr show assoc list them). Besides type, cluster takes the cluster class's arguments. On every scheduler but LSF, their defaults are 1 core, 1 process and 4GB per worker job (and 1GB of disk on HTCondor), and no time limit: the queue decides, unless you set walltime. Each worker job does cores runs at the same time.

What works where qa batch runs, and from the QA-Board server:

cluster.typeqa batch--no-wait sends a driver job withCtrl-C and stopping from the web app
lsfNeeds bsubbsub, or the LSF bridgebkill; the server goes through the LSF bridge
slurmNeeds sbatchsbatchscancel; the server needs it in its image
pbs, moabNeeds qsub (Moab: msub)qsub (Moab: msub)qselect and qdel; the server needs them in its image. Moab must run on Torque or PBS
sgeNeeds qsubqsubqdel; the server needs it in its image
htcondorNeeds condor_submitcondor_submitcondor_rm; the server needs it in its image
oarNeeds oarsuboarsuboardel; the server needs it in its image
kubernetesNeeds the Dask operator in the clusterA pod, like the kubernetes runner'sDeletes the DaskCluster and the driver's Job; the server needs the namespace
localStarts the workers on this machineA background process on this machineCtrl-C only: kill the driver, its PID is in driver.pid

Jobs are cancelled by their name: <batch-prefix>_dask for the workers and <batch-prefix>_dask_driver for the --no-wait driver on LSF, qa<batch-prefix>_dask and qa<batch-prefix>_drv on the other schedulers, where <batch-prefix> is the first 8 characters of the batch's command id. On Slurm, PBS, SGE, HTCondor and OAR, the QA-Board server only cancels the jobs of the user who started the batch. The QA-Board server's image doesn't have Slurm, PBS, SGE, HTCondor or OAR's commands: your QA-Board admins add them to stop these batches from the web app.

OAR

On OAR, set walltime (and driver.walltime for --no-wait): otherwise dask-jobqueue's default applies, and the jobs are killed after 30 minutes. qa doctor warns about it. The --no-wait driver also gets OAR's login environment, not yours: OAR can't forward it.

Dask on Kubernetes​

With type: kubernetes, the workers are pods that the Dask Kubernetes operator starts. Your cluster's admins install the operator once, and you install qaboard[dask-kubernetes]. The pods are like the kubernetes runner's: their image, namespace, resources, user (run_as), mounts, image pull secrets, node selector and tolerations come from runners.kubernetes, and cluster can change the image, namespace, resources and environment:

qaboard.yaml
runners:
default: dask
kubernetes:
namespace: <your-namespace>
image: <your-image> # with qa, distributed and your code's dependencies
resources: {cpu: 4, memory: 16Gi}
mounts:
- path: /mnt/qaboard
pvc: <your-claim>
dask:
concurrency: 20
cluster:
type: kubernetes
threads_per_worker: 4 # runs per worker pod (default: 1)
  • Each qa batch creates its own DaskCluster, qa-<batch-prefix>-dask-<random>, labeled like the kubernetes runner's Jobs, with the batch's command id, user and project (the operator puts the labels on the pods too), and deletes it when the batch ends. If qa batch dies, the operator deletes it once idle for idle_timeout (600 seconds by default). Stopping the batch from QA-Board deletes the DaskClusters and the driver's Job that have its command id and project.
  • The scheduler pod asks for 1 CPU and 2Gi of memory, without the mounts, node selector and tolerations of the workers. All the pods get the kubernetes runner's security context: no privilege escalation, no capabilities, the default seccomp profile, and runAsNonRoot when they run as a UID.
  • Runs execute where you started qa batch, at the paths you see, like with the kubernetes runner: a folder you reach through a symbolic link keeps the link's path, the one the pods mount.
  • Dask uses your kubeconfig's current context (in a pod, its ServiceAccount): qa batch stops if runners.kubernetes.context names another one.
  • The runs get your environment variables, secrets included (they go to the workers through Dask, not in a ConfigMap), without those of your machine like PATH and HOME.
  • Your permissions in the namespace: qa doctor checks them, and prints the Role to ask your admins for.
The Dask scheduler has no authentication

Anyone who can reach the scheduler's pod can send it tasks, which run on the workers as your user, with your files, and read the tasks it holds: they carry the runs' environment, secrets included. Restrict who can reach the DaskClusters' pods with a NetworkPolicy, if your cluster enforces them:

dask-network-policy.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: qaboard-dask
namespace: <your-namespace>
spec:
# the schedulers and workers of QA-Board's DaskClusters
podSelector:
matchLabels:
app.kubernetes.io/managed-by: qaboard
matchExpressions:
- {key: dask.org/cluster-name, operator: Exists}
policyTypes: [Ingress]
ingress:
- from:
# QA-Board's pods in the namespace: workers, schedulers, --no-wait drivers
- podSelector:
matchLabels:
app.kubernetes.io/managed-by: qaboard
# the Dask operator, which checks if schedulers are idle
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: dask-operator

qa batch outside the cluster reaches the scheduler with a port-forward through the API server, which needs the pods/portforward permission and isn't blocked by the policy. Other users' batches in the namespace match the policy too: like for the kubernetes runner, the namespace is the trust boundary.

For one pod per run, or several runs per pod, without Dask, see the kubernetes runner.

How it works​

  1. qa batch starts a Dask scheduler in its own process (on Kubernetes, the operator starts a scheduler pod).
  2. It starts ceil(min(#runs, concurrency) / cores) worker jobs, named after the batch (see above).
  3. It keeps at most concurrency runs in flight: a new run starts as soon as one finishes.
  4. When all runs are done, the worker jobs are stopped.

If the scheduler refuses the worker jobs (an unknown queue, too many resources...), qa batch stops with its error. If no worker starts within worker_start_timeout seconds, it stops too: by default after 15 minutes on Kubernetes and with local, and never on the other schedulers, whose queues can be long.

With --no-wait, steps 1-4 happen in a "driver" job, and qa batch returns as soon as it is sent. It needs little, and runs until the last run ends:

  • On LSF, it gets the options of runners.dask.driver, by default those of runners.lsf, so it doesn't take e.g. a GPU slot.
  • On Kubernetes, runners.dask.driver changes the options of runners.kubernetes for its pod. Its ServiceAccount creates the DaskCluster: it needs the same permissions as you.
  • On Slurm, PBS, SGE..., it gets the workers' settings (queue, account...) without their resources and time limit: 1 core and 2GB, and what runners.dask.driver sets, e.g. a walltime long enough for the whole batch. It gets your environment (sbatch --export=ALL, qsub -V...), and starts the workers from the node it runs on.

Logs​

  • Each run's output is saved in its output directory as log.dask.txt (in addition to the usual log.txt).
  • Everything else is in the batch directory, under dask/{batch-prefix}/:
    • worker logs: *.err has Dask's logs, and a [qaboard] start / [qaboard] end line per run. *.out is usually empty.
    • with --no-wait: driver.log (live progress), driver.lsf.log (LSF's report, at the end) and tasks.json (the runs it was asked to execute).
  • Your environment variables are forwarded to the runs, except those specific to your host or scheduler job (LSB_*, SLURM_*, PBS_*, TMPDIR, CUDA_VISIBLE_DEVICES...).
  • Stopping a batch from QA-Board cancels the worker and driver jobs (on LSF: bkill -J "{batch-prefix}*"). Ctrl-C on qa batch kills the running runs and the workers.
  • If a worker job dies while running something (e.g. killed by LSF for using too much memory), Dask retries the run on another worker, up to 3 times.
Requirements & limitations
  • Workers open a TCP connection to the host running qa batch. It's usually fine within a cluster; otherwise set cluster.interface.
  • Without --no-wait, bsub must be available where qa batch runs: LSF "bridges" are not supported. With --no-wait, the driver is sent via the bridge like other LSF jobs, and it then starts the workers itself.
  • All workers get the same LSF options: per-input-type LSF options (e.g. more memory for some inputs) are not applied. Size memory for your heaviest runs.
  • Worker jobs are kept until the batch ends, even if idle while the last runs finish.

Using an existing Dask cluster​

If you keep a Dask cluster running (e.g. dask scheduler on a host, and dask worker tcp://host:8786 sent with bsub), point to it:

qaboard.yaml
runners:
dask:
scheduler_address: tcp://my-host:8786
concurrency: 20
  • qa batch doesn't start or stop workers: the cluster size is the global limit, concurrency the limit of each qa batch.
  • With --no-wait, a driver job of cluster.type connects to the cluster and keeps at most concurrency runs in flight. If qa batch can't send one from where it runs (e.g. no bsub and no QA_RUNNERS_LSF_BRIDGE for lsf), all runs are sent at once and concurrency is not enforced. qa doctor warns about it.
  • To stop batches from QA-Board, the QA-Board server needs distributed installed, access to the scheduler, and the scheduler's address in QABOARD_DASK_SCHEDULERS.

Troubleshooting​

  • Nothing starts: check the jobs (bjobs -J "{batch-prefix}_dask*" on LSF, squeue --name qa{batch-prefix}_dask on Slurm), and the logs in {batch-dir}/dask/{batch-prefix}/.
  • Workers start but runs don't: check they reached the scheduler (Registered to: in the worker's .err), then the [qaboard] start lines, then the runs' log.dask.txt.
  • QA_BATCH_VERBOSE=1 qa batch ... prints the worker job script.