-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nprocs auto option to dask-worker CLI (#4377)
- Loading branch information
1 parent
8f33b9e
commit 5812314
Showing
6 changed files
with
66 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from distributed.deploy.utils import nprocesses_nthreads | ||
|
||
|
||
def test_default_process_thread_breakdown(): | ||
assert nprocesses_nthreads(1) == (1, 1) | ||
assert nprocesses_nthreads(4) == (4, 1) | ||
assert nprocesses_nthreads(5) == (5, 1) | ||
assert nprocesses_nthreads(8) == (4, 2) | ||
assert nprocesses_nthreads(12) in ((6, 2), (4, 3)) | ||
assert nprocesses_nthreads(20) == (5, 4) | ||
assert nprocesses_nthreads(24) in ((6, 4), (8, 3)) | ||
assert nprocesses_nthreads(32) == (8, 4) | ||
assert nprocesses_nthreads(40) in ((8, 5), (10, 4)) | ||
assert nprocesses_nthreads(80) in ((10, 8), (16, 5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import math | ||
|
||
from dask.system import CPU_COUNT | ||
from dask.utils import factors | ||
|
||
|
||
def nprocesses_nthreads(n=CPU_COUNT): | ||
""" | ||
The default breakdown of processes and threads for a given number of cores | ||
Parameters | ||
---------- | ||
n: int | ||
Number of available cores | ||
Examples | ||
-------- | ||
>>> nprocesses_nthreads(4) | ||
(4, 1) | ||
>>> nprocesses_nthreads(32) | ||
(8, 4) | ||
Returns | ||
------- | ||
nprocesses, nthreads | ||
""" | ||
if n <= 4: | ||
processes = n | ||
else: | ||
processes = min(f for f in factors(n) if f >= math.sqrt(n)) | ||
threads = n // processes | ||
return (processes, threads) |