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.
- 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:
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.type | Workers are | Settings |
|---|---|---|
lsf (default) | LSF jobs | LSFCluster, with defaults from runners.lsf |
slurm | Slurm jobs | SLURMCluster |
pbs | PBS jobs | PBSCluster |
sge | SGE jobs | SGECluster |
htcondor | HTCondor jobs | HTCondorCluster |
oar | OAR jobs | OARCluster |
moab | Moab jobs | MoabCluster |
kubernetes | Pods, with the Dask Kubernetes operator | KubeCluster; the image, namespace, resources and user default to runners.kubernetes |
local | Processes on the machine that runs qa batch | LocalCluster, for big machines and tests |
On Slurm, with 4 runs per worker job:
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.type | qa batch | --no-wait sends a driver job with | Ctrl-C and stopping from the web app |
|---|---|---|---|
lsf | Needs bsub | bsub, or the LSF bridge | bkill; the server goes through the LSF bridge |
slurm | Needs sbatch | sbatch | scancel; the server needs it in its image |
pbs, moab | Needs qsub (Moab: msub) | qsub (Moab: msub) | qselect and qdel; the server needs them in its image. Moab must run on Torque or PBS |
sge | Needs qsub | qsub | qdel; the server needs it in its image |
htcondor | Needs condor_submit | condor_submit | condor_rm; the server needs it in its image |
oar | Needs oarsub | oarsub | oardel; the server needs it in its image |
kubernetes | Needs the Dask operator in the cluster | A pod, like the kubernetes runner's | Deletes the DaskCluster and the driver's Job; the server needs the namespace |
local | Starts the workers on this machine | A background process on this machine | Ctrl-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.
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:
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 batchcreates 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. Ifqa batchdies, the operator deletes it once idle foridle_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
runAsNonRootwhen 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 batchstops ifrunners.kubernetes.contextnames 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
PATHandHOME. - Your permissions in the namespace:
qa doctorchecks them, and prints the Role to ask your admins for.
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:
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
qa batchstarts a Dask scheduler in its own process (on Kubernetes, the operator starts a scheduler pod).- It starts
ceil(min(#runs, concurrency) / cores)worker jobs, named after the batch (see above). - It keeps at most
concurrencyruns in flight: a new run starts as soon as one finishes. - 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 ofrunners.lsf, so it doesn't take e.g. a GPU slot. - On Kubernetes,
runners.dask.driverchanges the options ofrunners.kubernetesfor 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.driversets, e.g. awalltimelong 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 usuallog.txt). - Everything else is in the batch directory, under
dask/{batch-prefix}/:- worker logs:
*.errhas Dask's logs, and a[qaboard] start/[qaboard] endline per run.*.outis usually empty. - with
--no-wait:driver.log(live progress),driver.lsf.log(LSF's report, at the end) andtasks.json(the runs it was asked to execute).
- worker logs:
- 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-Conqa batchkills 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.
- Workers open a TCP connection to the host running
qa batch. It's usually fine within a cluster; otherwise setcluster.interface. - Without
--no-wait,bsubmust be available whereqa batchruns: 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
memoryfor 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:
runners:
dask:
scheduler_address: tcp://my-host:8786
concurrency: 20
qa batchdoesn't start or stop workers: the cluster size is the global limit,concurrencythe limit of eachqa batch.- With
--no-wait, a driver job ofcluster.typeconnects to the cluster and keeps at mostconcurrencyruns in flight. Ifqa batchcan't send one from where it runs (e.g. nobsuband noQA_RUNNERS_LSF_BRIDGEforlsf), all runs are sent at once andconcurrencyis not enforced.qa doctorwarns about it. - To stop batches from QA-Board, the QA-Board server needs
distributedinstalled, access to the scheduler, and the scheduler's address inQABOARD_DASK_SCHEDULERS.
Troubleshooting
- Nothing starts: check the jobs (
bjobs -J "{batch-prefix}_dask*"on LSF,squeue --name qa{batch-prefix}_daskon 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] startlines, then the runs'log.dask.txt. QA_BATCH_VERBOSE=1 qa batch ...prints the worker job script.