Repository navigation
Add acceptance test that fails when a package init() is slow #7406
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
Merged
+69
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2dc7448
Add acceptance test that fails when a package init() is slow
pietern 96b9183
Format init time budgets with a fixed two-decimal width
pietern d187bdb
Log init times on all OSes and fail on total init time on Linux
pietern 9907152
Drop historical reference from inittime script
pietern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Report each Go package's init() clock time (GODEBUG=inittrace=1) on stderr and, on Linux, | ||
| fail if the total init time exceeds --max-ms. | ||
|
|
||
| The total is judged by its minimum over several runs, since load from parallel tests | ||
| inflates individual runs but slow inits are slow on every run. While the total is over the | ||
| threshold, more runs are added (up to --max-runs) to ride out bursts of load. | ||
| """ | ||
|
|
||
| import argparse | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import sys | ||
|
|
||
| INIT_LINE = re.compile(r"^init (\S+) @\S+ ms, (\S+) ms clock") | ||
|
|
||
|
|
||
| def measure(command): | ||
| env = dict(os.environ, GODEBUG="inittrace=1") | ||
| cp = subprocess.run(command, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True) | ||
| if cp.returncode != 0: | ||
| sys.exit(f"command failed with exit code {cp.returncode}:\n{cp.stderr}") | ||
| clocks = {m.group(1): float(m.group(2)) for m in map(INIT_LINE.match, cp.stderr.splitlines()) if m} | ||
| if not clocks: | ||
| sys.exit(f"no inittrace output from {command}:\n{cp.stderr}") | ||
| return clocks | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--runs", type=int, default=5) | ||
| parser.add_argument("--max-runs", type=int, default=20) | ||
| parser.add_argument("--max-ms", type=float, required=True) | ||
| parser.add_argument("command", nargs="+") | ||
| args = parser.parse_args() | ||
|
|
||
| runs = [measure(args.command) for _ in range(args.runs)] | ||
| while len(runs) < args.max_runs and min(sum(r.values()) for r in runs) > args.max_ms: | ||
| runs.append(measure(args.command)) | ||
|
|
||
| total = min(sum(r.values()) for r in runs) | ||
| clocks = {pkg: min(r[pkg] for r in runs) for pkg in runs[0]} | ||
| print(f"Minimum init() clock time in ms over {len(runs)} runs:", file=sys.stderr) | ||
| print(f"{total:5.2f} total", file=sys.stderr) | ||
| for pkg, ms in sorted(clocks.items(), key=lambda kv: (-kv[1], kv[0])): | ||
| print(f"{ms:5.2f} {pkg}", file=sys.stderr) | ||
|
|
||
| # Clocks elsewhere are too coarse or noisy to enforce (on Windows they can be quantized | ||
| # to the ~15.6 ms system tick). | ||
| if total > args.max_ms and sys.platform == "linux": | ||
| print( | ||
| f"FAIL: package init() takes {total:.2f} ms in total, over {args.max_ms:g} ms; this delays every CLI invocation." | ||
| ) | ||
| print("To investigate:") | ||
| print(" GODEBUG=inittrace=1 databricks --version 2>&1 | sort -k5 -n -r | head") | ||
| print(" go mod why -m <module>") | ||
| sys.exit(1) | ||
| print(f"OK: total package init() time is within {args.max_ms:g} ms") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Cloud = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| OK: total package init() time is within 10 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Package init() runs on every CLI invocation, so slow inits (often arriving through a | ||
| # transitive dependency upgrade) delay every command. The total is ~5 ms on linux/amd64. | ||
| check_init_time.py --max-ms 10 -- $CLI --version 2> LOG.inittime |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just run it here and record output? For historical runs. Can also drop sort and head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYM for historical runs?
We already capture the timing in the log output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do it in a follow up if we need to.