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

Use a pool for dart actions to avoid OOMs #27781

Merged
merged 3 commits into from
Jul 30, 2021

Conversation

zanderso
Copy link
Member

Limits the level of concurrency of actions that run Dart programs during the build. This is to avoid e.g. too many invocations of the front end running at the same time and exhausting system memory, which results in build failures.

FIxes flutter/flutter#86946

@zanderso zanderso added the Work in progress (WIP) Not ready (yet) for review! label Jul 29, 2021
@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Jul 29, 2021
@google-cla google-cla bot added the cla: yes label Jul 29, 2021
Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Some minor nits about more error handling and documentation. But otherwise LGTM.

@@ -0,0 +1,102 @@
#!/usr/bin/env python3
# Copyright 2019 The Fuchsia Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Is this copyright script meant to remain as-is? Presumably, this script is from the Fuchsia buildroot then?

Copy link
Member

Choose a reason for hiding this comment

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

I see, it's this but with added Windows support. I'll review the delta.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's from the Fuchsia buildroot. It looks like for other files from the Fuchsia buildroot we're leaving the Fuchsia copyright header.

build/get_concurrent_jobs.py Outdated Show resolved Hide resolved
parser = argparse.ArgumentParser()
parser.add_argument(
"--memory-per-job", action=ParseSizeAction, default=[], nargs='*')
parser.add_argument("--reserve-memory", type=ParseSize, default=0)
Copy link
Member

Choose a reason for hiding this comment

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

I am not able to tell what the reserve memory flag is meant to do by just reading the flag name. Reserve memory for what? Perhaps add a help= argument to the parser? From my reading of the code, something like "Amount of total memory to reserve for activity unrelated to all jobs in the pool"? Come to think of it, since the caller doesn't know what the total memory is, perhaps this argument should be some percent of total memory? Say, something like 10% off the top.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added help text. Whether a percent or an absolute value, it's a bit of a blind guess at how much the system needs to keep for itself to avoid thrashing. I'd actually be more worried about a percent as far as that goes. On a small machine it might not be enough, and on a big machine it will be too much.

_args = [
"--reserve-memory=1GB",
"--memory-per-job",
"dart=1GB",
Copy link
Member

Choose a reason for hiding this comment

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

I was trying to figure out why memory-per-job was a key value pair but it looks like you are going to extend this for other things as well. Perhaps something for the linker when LTO is enabled maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the Chromium and Fuchsia builds use this in LTO builds. We should probably consider doing that as well after profiling.

parser.add_argument("--reserve-memory", type=ParseSize, default=0)
args = parser.parse_args()

total_memory = GetTotalMemory()
Copy link
Member

Choose a reason for hiding this comment

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

If total_memory is zero (as it could be in the error cases), perhaps just quit and return a default json with job counts of 1? I am not sure how robust GetTotalMemory is to error, or (for that matter) GN is to zero job counts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comments.

@zanderso zanderso removed the Work in progress (WIP) Not ready (yet) for review! label Jul 30, 2021
@zanderso zanderso merged commit d71ba56 into flutter:master Jul 30, 2021
@zanderso zanderso deleted the try-dart-pool branch July 30, 2021 06:43
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 30, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 30, 2021
naudzghebre pushed a commit to naudzghebre/engine that referenced this pull request Sep 2, 2021
* Use a pool for dart actions to avoid OOMs

* Add Windows support
filmil pushed a commit to filmil/engine that referenced this pull request Apr 21, 2022
* Use a pool for dart actions to avoid OOMs

* Add Windows support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use GN pools for Dart compiler invocations during the engine build
2 participants