-
Notifications
You must be signed in to change notification settings - Fork 48
Worker ID functionality #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pmla
wants to merge
15
commits into
joblib:master
Choose a base branch
from
pmla:worker-id
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
edeb407
worker ID functionality
pmla 229a469
removed debug prints
pmla 7033961
removed `next`
pmla 949169d
test that worker_id return value is appropriate
pmla 979fef2
Update loky/process_executor.py
pmla 4c5f5e5
Update loky/process_executor.py
pmla 44bb17d
pass worker_id as a function argument
pmla 93927db
docstring
pmla d0f4320
document problems with resizing
pmla 4be8b04
added timeout test
pmla 7e05644
Update loky/process_executor.py
pmla 4d8b594
Update loky/worker_id.py
pmla 6abad2c
Update tests/test_worker_id.py
pmla 5b18fa0
removed redundant if-statement
pmla b66b607
Merge branch 'master' into worker-id
tomMoral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
import os | ||
|
||
|
||
def get_worker_id(): | ||
"""Get the worker ID of the current process. | ||
|
||
For a `ReusableExectutor` with `max_workers=n`, the worker ID is in the | ||
range [0..n). This is suited for reuse of persistent objects such as GPU | ||
IDs. This function only works at the first level of parallelization (i.e. | ||
not for nested parallelization). Resizing the `ReusableExectutor` will | ||
result in unpredictable return values. | ||
|
||
Returns -1 when the process is not a worker. | ||
""" | ||
return int(os.environ.get('LOKY_WORKER_ID', -1)) |
This file contains hidden or 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,36 @@ | ||
import time | ||
import pytest | ||
import numpy as np | ||
from collections import defaultdict | ||
from loky import get_reusable_executor, get_worker_id | ||
|
||
|
||
def random_sleep(args): | ||
k, max_duration = args | ||
rng = np.random.RandomState(seed=k) | ||
duration = rng.uniform(0, max_duration) | ||
t0 = time.time() | ||
time.sleep(duration) | ||
t1 = time.time() | ||
wid = get_worker_id() | ||
return (wid, t0, t1) | ||
|
||
|
||
@pytest.mark.parametrize("max_duration,timeout,kmax", [(0.05, 2, 100), | ||
(1, 0.01, 4)]) | ||
def test_worker_ids(max_duration, timeout, kmax): | ||
"""Test that worker IDs are always unique, with re-use over time""" | ||
num_workers = 4 | ||
executor = get_reusable_executor(max_workers=num_workers, timeout=timeout) | ||
results = executor.map(random_sleep, [(k, max_duration) | ||
for k in range(kmax)]) | ||
|
||
all_intervals = defaultdict(list) | ||
for wid, t0, t1 in results: | ||
assert wid in set(range(num_workers)) | ||
all_intervals[wid].append((t0, t1)) | ||
|
||
for intervals in all_intervals.values(): | ||
intervals = sorted(intervals) | ||
for i in range(len(intervals) - 1): | ||
assert intervals[i + 1][0] >= intervals[i][1] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.