Skip to content
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

Dask task affinity! #1229

Merged
merged 5 commits into from
Jul 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
First pass implementation at dask task affinity tags
  • Loading branch information
cicdw committed Jul 13, 2019
commit 974e5df3d8d3b38fc8a4aef370b5f90559a1f7c0
15 changes: 15 additions & 0 deletions src/prefect/engine/executors/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,25 @@ def submit(self, fn: Callable, *args: Any, **kwargs: Any) -> Future:
Returns:
- Future: a Future-like object that represents the computation of `fn(*args, **kwargs)`
"""
## set a key for the dask scheduler UI
if context.get("task_full_name"):
key = context.get("task_full_name", "") + "-" + str(uuid.uuid4())
else:
key = None

## infer from context if dask resources are being utilized
dask_resource_tags = [
tag
for tag in context.get("task_tags", [])
if tag.lower().startswith("dask-resource")
]
if dask_resource_tags:
resources = {}
for tag in dask_resource_tags:
prefix, val = tag.split("=")
resources.update({prefix.split(":")[1]: float(val)})
kwargs.update(resources=resources)

if self.is_started and hasattr(self, "client"):
future = self.client.submit(fn, *args, pure=False, key=key, **kwargs)
elif self.is_started:
Expand Down
4 changes: 3 additions & 1 deletion src/prefect/engine/task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def initialize_run( # type: ignore
if isinstance(state, Resume):
context.update(resume=True)

context.update(task_run_count=run_count, task_name=self.task.name)
context.update(
task_run_count=run_count, task_name=self.task.name, task_tags=self.task.tags
)

return TaskRunnerInitializeResult(state=state, context=context)

Expand Down
13 changes: 13 additions & 0 deletions tests/engine/test_task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ def test_task_runner_puts_resume_in_context_if_state_is_resume(self):
result = TaskRunner(Task()).initialize_run(state=Resume(), context=ctx)
assert result.context.resume is True

def test_task_runner_puts_tags_in_context(self):
with prefect.context() as ctx:
assert "task_tags" not in ctx
result = TaskRunner(Task()).initialize_run(state=None, context=ctx)
assert result.context.task_tags == set()

with prefect.context() as ctx:
assert "task_tags" not in ctx
result = TaskRunner(Task(tags=["foo", "bar"])).initialize_run(
state=None, context=ctx
)
assert result.context.task_tags == {"foo", "bar"}

@pytest.mark.parametrize(
"state", [Success(), Failed(), Pending(), Scheduled(), Skipped(), Cached()]
)
Expand Down