Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use cached boto3 clients in ECSWorker #375

Merged
merged 5 commits into from
Jan 29, 2024
Merged

Conversation

kevingrismore
Copy link
Contributor

@kevingrismore kevingrismore commented Jan 27, 2024

Closes PrefectHQ/prefect#7805

Replaces the use of a session object for client creation with a single cached client per client type in the ECS worker. Significantly reduces memory usage when handling multiple flow runs.

Screenshots

Relative memory consumption (depicted by width of allocating call stack) during 50 simultaneous deployment runs, before and after:

Peak memory usage: 902.5 MiB
image

Peak memory usage: 45.5 MiB
image

Checklist

  • References any related issue by including "Closes #" or "Closes ".
    • If no issue exists and your change is not a small fix, please create an issue first.
  • Includes tests or only affects documentation.
  • Passes pre-commit checks.
    • Run pre-commit install && pre-commit run --all locally for formatting and linting.
  • Includes screenshots of documentation updates.
    • Run mkdocs serve view documentation locally.
  • Summarizes PR's changes in CHANGELOG.md

@kevingrismore kevingrismore marked this pull request as ready for review January 27, 2024 18:39
@kevingrismore kevingrismore requested a review from a team as a code owner January 27, 2024 18:39
Copy link
Contributor

@urimandujano urimandujano left a comment

Choose a reason for hiding this comment

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

Nice work, the improvements in your screenshot are incredible!

@desertaxle
Copy link
Member

We recently added client caching for AwsCredentials in #369. Does that solve the issue or do we need additional caching at the ECSWorker layer?

@kevingrismore
Copy link
Contributor Author

kevingrismore commented Jan 29, 2024

We recently added client caching for AwsCredentials in #369. Does that solve the issue or do we need additional caching at the ECSWorker layer?

This change just takes advantage of the caching from AwsCredentials as previously the worker was grabbing a session from the credentials and building multiple clients via one of the session's methods.

This only wouldn't be advantageous if someone was running lots of deployments, and each of those deployments had unique AwsCredentials.

@kevingrismore kevingrismore merged commit ac19635 into main Jan 29, 2024
6 checks passed
@kevingrismore kevingrismore deleted the worker-use-cached-client branch January 29, 2024 17:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate Prefect 2 Agent Memory Consumption
3 participants