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

Enable Eager Workflow Start #430

Merged
merged 4 commits into from
Nov 27, 2023

Conversation

antlai-temporal
Copy link
Contributor

Enables Eager Workflow Start for Python SDK after being enabled in Core. This is an experimental feature that
reduces the latency to start a workflow by dispatching the first task directly to a worker that shares the client with the initiator.

Checklist

  1. Closes
    [Feature Request] Eager workflow start #388

@antlai-temporal antlai-temporal requested a review from a team as a code owner November 16, 2023 22:45
@CLAassistant
Copy link

CLAassistant commented Nov 16, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of naming discussions, but otherwise LGTM

Comment on lines 453 to 455
eager_start: Reduce the latency to start this workflow.
It requires that the client is shared between the worker and the starter.
This is currently experimental.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eager_start: Reduce the latency to start this workflow.
It requires that the client is shared between the worker and the starter.
This is currently experimental.
eager_start: Potentially reduce the latency to start this workflow by
encouraging the server to start it on a local worker running with
this same client.
This is currently experimental.

Pedantic, don't have to change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much clear, thanks!

@@ -1074,6 +1089,7 @@ def __init__(
result_run_id: Optional[str] = None,
first_execution_run_id: Optional[str] = None,
result_type: Optional[Type] = None,
eager_start_active: bool = False,
Copy link
Member

@cretz cretz Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmm, I'm not sure this should be on the handle. Usually the only things on a handle are things that have actual usage value for the handle regardless of whether it was created via start or whether the handle is created via get_workflow_handle or whether this constructor is called manually. This has only read value and only in one case of handle creation.

We don't tell a user on their activity handle that their activity was eagerly started either and that has seemed ok to everyone. Go and Java don't show this anywhere I can see and we're ok with that there. I think we can use a metric or something else to tell a user (and a test) that workflows were started eagerly. I think we can punt on reporting this to users via the handle at first and maybe revisit when a user requests it.

If we do decide to expose this, I think it should not be on the constructor (i.e. late bound directly on the private attribute) and changed to "eagerly started". So:

  • Remove this constructor param
  • Change init code to be self._eagerly_started = False
  • Change property name to be def eagerly_started(self) -> bool: and remove docstring about cannot be mutated (implied for read-only property)
  • Set the attribute post-construction in the workflow starter code

I could also be convinced of "started eagerly" instead of "eagerly started" though I like the latter because it matches the parameter name from start/execute.

But still, I am not sure that Python deserves to expose this any more than Go or Java do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eagerly_started is much better. I'll change it not to be in the constructor. It is hard to add this in other way, we only have server-side metrics for eager, and that's difficult to synchronize... And I think that once customers start enabling eager, the first question is "is it working?" and we want to provide a simple way to check that. I'll talk with @Quinn-With-Two-Ns to expose this in Java and Go too...

Copy link
Member

@cretz cretz Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I would like to have the discussion of how we may expose in Go and Java before exposing in Python. If we find our two most used SDKs haven't/don't need to expose that they started eagerly besides metrics, I would rather not in Python.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing "eagerly started" from handle to be consistent with other SDKs

@@ -287,6 +287,7 @@ async def start_workflow(
start_signal_args: Sequence[Any] = [],
rpc_metadata: Mapping[str, str] = {},
rpc_timeout: Optional[timedelta] = None,
eager_start: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eager_start: bool = False,
request_eager_start: bool = False,

I wonder if this is a bit clearer (or "enable eager start" or "suggest eager start" or something that doesn't imply any guarantees)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about not implying guarantees, changing it...

@cretz
Copy link
Member

cretz commented Nov 27, 2023

Looks good! Had to merge main into your branch, will merge into main if/when CI succeeds.

@cretz cretz merged commit c47e3f1 into temporalio:main Nov 27, 2023
@antlai-temporal
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants