<p>I will run mutultiples executions of an algorithm on Kubernetes with <a href="https://kubernetes.dask.org/en/latest/kubecluster.html" rel="nofollow noreferrer">Dask KubeCluster</a>. I want a worker to run one and only one algorithm, so I'm confused with <code>nthreads</code> argument passed to the dask-worker at initialization.</p>
<pre><code>kind: Pod
metadata:
  labels:
    app: MyName
spec:
  restartPolicy: Never
  containers:
  - image: MyFunnyDockerImage
    imagePullPolicy: Always
    args: [dask-worker, --nthreads, '4', --no-dashboard, --memory-limit, 8GB, --death-timeout, '60']
    name: execslotting

    resources:
      limits:
        cpu: &quot;4&quot;
        memory: 8G
      requests:
        cpu: &quot;4&quot;
        memory: 8G

  imagePullSecrets: 
    - name: acr-secret
</code></pre>
<p>When I set <code>--nthreads=4</code> am I leaving the possibility that 4 executions of my algorithm will be run in that worker?</p>

Andrex
<p>The <code>nthreads</code> argument speciefies the number of threads on the host machine or pod that the dask worker process can use for running computations. See the <a href="http://distributed.dask.org/en/latest/worker.html#thread-pool" rel="nofollow noreferrer">Dask worker docs here</a>.</p>
<p>When you set <code>--nthreads=4</code> you're telling Dask that the worker process can use 4 threads, regardless of how many threads are available on that pod. If for example your pod has 8 threads available Dask would only use half of those if you specify <code>--nthreads=4</code>.</p>
<p>Also see the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#cpu-units" rel="nofollow noreferrer">Kubernetes docs on CPU units</a> for a more detailed explanation of how vCPU units relate to threads in Kubernetes.</p>
<p>If you do not specify <code>nthreads</code>, then Dask will set a sane default using as many threads as there are CPU cores available on your machine, which seems to match the way Kubernetes handles multithreading (1 vCPU = 1 Hyperthread).</p>
<p>In your example, you have set <code>resources.requests.cpu=4</code> which means that pod will have 4 threads available for use. So setting <code>--nthreads=4</code> will allow the Dask worker process to make full use of that pods resources. Although I believe not setting <code>nthreads</code> will achieve the same result.</p>
