-
Notifications
You must be signed in to change notification settings - Fork 0
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
Improve bom generation #51
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c610e1f
Improve BOM generation perf by iterating files in parallel
kdumontnu 40f9bce
Sort BOM generated output
kdumontnu ba9525c
Make BOM generation test repeatable
kdumontnu f6e1f8c
Enforce newline ending
kdumontnu aeaa67f
Move sleep counter out of loop so that we don't blast the servers if …
kdumontnu 88114bc
Make sort_function name more descriptive
kdumontnu f40211a
Add error if file fails to generate
kdumontnu 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 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 |
---|---|---|
|
@@ -248,31 +248,39 @@ def _extract_all_schdoc_components( | |
""" | ||
|
||
files_in_repo = repository.get_git_content(ref=ref) | ||
all_components = [] | ||
for repo_file in files_in_repo: | ||
if repo_file.name in schdoc_files_in_proj: | ||
# If the file is not yet generated, we'll retry a few times. | ||
retry_count = 0 | ||
while True: | ||
retry_count += 1 | ||
|
||
try: | ||
schdoc_file_json = repository.get_generated_json(repo_file, ref=ref) | ||
all_components.extend( | ||
_extract_components_from_schdoc( | ||
schdoc_file_json, | ||
attributes_mapping, | ||
) | ||
) | ||
|
||
break | ||
except NotYetGeneratedException: | ||
if retry_count > 20: | ||
break | ||
schdoc_files_in_repo = [file for file in files_in_repo if file.name in schdoc_files_in_proj] | ||
|
||
# Create a retry value for each file so that we can traverse them | ||
# in parallel for improved performance | ||
retry_counter = [60]*len(schdoc_files_in_repo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. retry_counters |
||
|
||
# Wait a bit before retrying. | ||
time.sleep(0.5) | ||
continue | ||
all_components = [] | ||
# If the file is not yet generated, we'll retry a few times. | ||
while any(i > 0 for i in retry_counter): | ||
for idx in range(len(retry_counter)): | ||
if retry_counter[idx] < 0: | ||
continue | ||
elif retry_counter[idx] == 0: | ||
raise Exception( | ||
f"Fetching file {schdoc_files_in_repo[idx].path} in {repository} ref={ref} exceeded max retries.") | ||
|
||
retry_counter[idx] -= 1 | ||
|
||
try: | ||
schdoc_file_json = repository.get_generated_json(schdoc_files_in_repo[idx], ref=ref) | ||
all_components.extend( | ||
_extract_components_from_schdoc( | ||
schdoc_file_json, | ||
attributes_mapping, | ||
) | ||
) | ||
retry_counter[idx] = -1 | ||
except NotYetGeneratedException: | ||
pass | ||
if any(retry_counter): | ||
# Wait a bit before retrying. | ||
time.sleep(0.25) | ||
|
||
return all_components | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -17,16 +17,13 @@ def get_all_pcb_components( | |
""" | ||
|
||
retry_count = 0 | ||
while True: | ||
while retry_count < 60: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can change this to a |
||
retry_count += 1 | ||
try: | ||
pcb_json = repository.get_generated_json(pcb_file, ref=ref) | ||
break | ||
return pcb_json["component_instances"] | ||
except NotYetGeneratedException: | ||
if retry_count > 20: | ||
break | ||
# Wait a bit before retrying. | ||
time.sleep(0.5) | ||
time.sleep(0.25) | ||
continue | ||
|
||
return pcb_json["component_instances"] | ||
raise Exception(f"Fetching file {pcb_file} in {repository} ref={ref} exceeded max retries.") |
This file contains 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
This file contains 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
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.
This comment is a little misleading. This code doesn't do anything in parallel. (Maybe round-robin is more accurate?) I would also use a pretty different approach. We basically want to reimplement the JS client code or something even smarter. But I don't know if we care. So I guess this is fine.
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.
Hmmm, maybe I should look at our rate-limiting a little closer. My goal here was to limit any requests by this function to 4 per second. I didn’t implement something with promises/threads because I figured that could still potentially fire off dozens of requests simultaneously, and rate-limit us, even if we waited between requests for each endpoint.
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.
Our rate limiting session should already limit requests to X per second. If it isn't limiting enough, then we should probably adjust the
max_calls
andperiod
arguments. The point of having a separate rate limiter is to pull out that concern so that rate limiting logic isn't sprinkled all over the codebase.py-allspice/allspice/ratelimiter.py
Lines 5 to 16 in 7fa7692
If you're interested, I can also post my pseudocode first draft of something that's more similar to the JS client code. It doesn't use promises or threads; that would be one of the improvements we could do.
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.
yeah, if you could share that it would be great
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.
See #58.