Skip to content

[serve][deploy refactor][4/X] Reconcile build app task - #37180

Merged
edoakes merged 10 commits into
ray-project:masterfrom
zcin:improve-deploy-4
Jul 12, 2023
Merged

edoakes merged 10 commits into
ray-project:masterfrom
zcin:improve-deploy-4

Conversation

@zcin

@zcin zcin commented Jul 7, 2023 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

This PR improves how the application state manager kicks off the task to import and build application code, and how the results are reconciled and then deployed.

  • When deploying from a config, the task should only import + build application then return the deploy arguments. The task should not call deploy API on the controller. The results will be fetched and reconciled by the application state manager.
  • If the "code version" inferred from the new config matches the old config, the task is not started - instead, only the updated config options will be applied to the deployment target states.
    • Note: this is not too different from how it worked before. What was happening before is that the application code is re-loaded every time the config is updated. Existing replicas would not be restarted because the deployment version is the same; but if (autoscaling is used and) new replicas are started, they are started with the new application code, meaning different replicas will have different versions of the application code! This change removes this inconsistency.

Related issue number

Checks

@zcin
zcin force-pushed the improve-deploy-4 branch 4 times, most recently from 7bc721e to ee2287d Compare July 7, 2023 21:19
Signed-off-by: Cindy Zhang <[email protected]>
@zcin
zcin force-pushed the improve-deploy-4 branch from ee2287d to c9e32f7 Compare July 7, 2023 22:14
zcin added 2 commits July 7, 2023 15:15
Signed-off-by: Cindy Zhang <[email protected]>
@zcin
zcin marked this pull request as ready for review July 7, 2023 23:57
@zcin
zcin requested a review from a team July 7, 2023 23:57

@edoakes edoakes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great overall.

One question about resetting the _build_app_task_info, otherwise small comments.

Comment thread python/ray/serve/_private/common.py Resolved
Comment thread python/ray/serve/built_application.py Outdated
Comment on lines +81 to +82
@property
def deploy_args_list(self) -> List[Dict]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

BuiltApplication is marked as a public API. To avoid maintaining this utility as a public API, can you make it a separate utility or a private method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've separated it out into a utility function!

)
elif check_obj_ref_ready_nowait(self._build_app_task_info.obj_ref):
build_app_obj_ref = self._build_app_task_info.obj_ref
self._build_app_task_info = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we are resetting this to None immediately, won't the following iteration always kick off a new build app task (because of the condition on line 427)? Or is that gated somewhere else?

@zcin zcin Jul 10, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's gated by line 524 - once the task finishes and the deploy args are fetched, the deploy args + the code version are applied to the target state through apply_deployment_args. Then in the next iteration, even though _build_app_task_info is None, since the current code version matches that of the target config, _start_or_reconcile_build_app_task isn't called.

It is a bit confusing, because we need to handle the target config being out of sync with the rest of the target state, and correctly detect that to bring the rest of the target state up to date. Resetting _build_app_task_info to None, coupled with the code version stored in _build_app_task_info, is one way I found that works for this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Got it. Without being as deep in the code as you I think it would be slightly preferable to make this function itself handle the case where the build task has already been run, but if this structure makes more sense to you then I'm OK with it.

Regardless, please add a comment about this assumption to the docstring of _start_or_reconcile_build_app_task and a short comment to the callsite saying that we should skip calling it when the code version already matches.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah I see! I've changed it so that the function is always called but will return a NO_TASK_STARTED status if there is no in progress task (nor does one need to be started).

Comment on lines +413 to +414
build task (resets self._build_app_task_info when task finishes,
regardless of whether it finished successfully)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Related to my comment below: what's the purpose of resetting self._build_app_task_info? Couldn't we instead mark it done and then short-circuit this method if the version matches the target version?

Might be missing this being handled at a higher layer somewhere.

Comment on lines +854 to +857
# Error is raised when this task is canceled with ray.cancel(), which
# happens when deploy_apps() is called.
logger.debug("Existing config deployment request terminated.")
return None, None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this seems a little sketchy, in a corner case it might cause application state to pick up None as the deploy args list

zcin added 4 commits July 10, 2023 14:25
Signed-off-by: Cindy Zhang <[email protected]>
Signed-off-by: Cindy Zhang <[email protected]>
Signed-off-by: Cindy Zhang <[email protected]>
@edoakes
edoakes merged commit f6ae1c7 into ray-project:master Jul 12, 2023
Bhav00 pushed a commit to Bhav00/ray that referenced this pull request Jul 28, 2023
…7180)

This PR improves how the application state manager kicks off the task to import and build application code, and how the results are reconciled and then deployed.

- When deploying from a config, the task should only import + build application then return the deploy arguments. The task should not call deploy API on the controller. The results will be fetched and reconciled by the application state manager.
- If the "code version" inferred from the new config matches the old config, the task is not started - instead, only the updated config options will be applied to the deployment target states.
  - Note: this is not too different from how it worked before. What was happening before is that the application code is re-loaded every time the config is updated. Existing replicas would not be restarted because the deployment version is the same; but if (autoscaling is used and) new replicas are started, they are started with the new application code, meaning different replicas will have different versions of the application code! This change removes this inconsistency.
NripeshN pushed a commit to NripeshN/ray that referenced this pull request Aug 15, 2023
…7180)

This PR improves how the application state manager kicks off the task to import and build application code, and how the results are reconciled and then deployed.

- When deploying from a config, the task should only import + build application then return the deploy arguments. The task should not call deploy API on the controller. The results will be fetched and reconciled by the application state manager.
- If the "code version" inferred from the new config matches the old config, the task is not started - instead, only the updated config options will be applied to the deployment target states.
  - Note: this is not too different from how it worked before. What was happening before is that the application code is re-loaded every time the config is updated. Existing replicas would not be restarted because the deployment version is the same; but if (autoscaling is used and) new replicas are started, they are started with the new application code, meaning different replicas will have different versions of the application code! This change removes this inconsistency.

Signed-off-by: NripeshN <[email protected]>
@zcin
zcin deleted the improve-deploy-4 branch August 25, 2023 17:34
arvind-chandra pushed a commit to lmco/ray that referenced this pull request Aug 31, 2023
…7180)

This PR improves how the application state manager kicks off the task to import and build application code, and how the results are reconciled and then deployed.

- When deploying from a config, the task should only import + build application then return the deploy arguments. The task should not call deploy API on the controller. The results will be fetched and reconciled by the application state manager.
- If the "code version" inferred from the new config matches the old config, the task is not started - instead, only the updated config options will be applied to the deployment target states.
  - Note: this is not too different from how it worked before. What was happening before is that the application code is re-loaded every time the config is updated. Existing replicas would not be restarted because the deployment version is the same; but if (autoscaling is used and) new replicas are started, they are started with the new application code, meaning different replicas will have different versions of the application code! This change removes this inconsistency.

Signed-off-by: e428265 <[email protected]>
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.

2 participants