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

Improve bom generation #51

Closed
wants to merge 7 commits into from
Closed

Improve bom generation #51

wants to merge 7 commits into from

Conversation

kdumontnu
Copy link
Contributor

@kdumontnu kdumontnu commented Oct 20, 2023

Depends on #50

  • Iterate schematic files in parallel instead of sequentially (eg. waiting for each one to return before parsing and moving to the next)
  • Add ACCEPT environment variable to regenerate the BOM output
  • Sort the BOM output both in the example code and in test code to make it repeatable
  • Add error condition when fetching design data

Base automatically changed from kd/pcb_netlist to main October 26, 2023 22:07
@kdumontnu kdumontnu changed the title Improve bom generation performance Improve bom generation Oct 27, 2023
Comment on lines +254 to +255
# Create a retry value for each file so that we can traverse them
# in parallel for improved performance
Copy link
Contributor

@jtran jtran Oct 27, 2023

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 and period 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.

class RateLimitedSession(requests.Session):
"""
A requests.Session that is rate limited.
:param max_calls: Maximum number of calls per period
:param period: Time period in seconds
Example:
session = RateLimitedSession(max_calls=10, period=1)
session.get("https://example.com") # Will be rate limited
"""

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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

See #58.


# 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

retry_counters

@@ -17,16 +17,13 @@ def get_all_pcb_components(
"""

retry_count = 0
while True:
while retry_count < 60:
Copy link
Contributor

Choose a reason for hiding this comment

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

We can change this to a for _ in range(60)

from allspice.utils.netlist_generation import generate_netlist

test_repo = "repo_" + uuid.uuid4().hex[:8]

accept_outputs = bool(os.getenv('ACCEPT'))
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to be consistent across repos this should be UPDATE_EXPECTED

@@ -51,6 +54,13 @@ def _setup_for_generation(instance, test_name):
)


def _bom_entry_sort_key(x: BomEntry) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should wrap the bom writing code and use it in the tests. Should avoid the duplication between the test and generate_bom.py file

@jtran jtran mentioned this pull request Oct 31, 2023
@shrik450
Copy link
Collaborator

shrik450 commented Jul 1, 2024

@kdumontnu Since this PR is considerably out of date now, I was thinking of creating issues for all the improvements here and closing it. Are you ok with that?

@kdumontnu
Copy link
Contributor Author

@kdumontnu Since this PR is considerably out of date now, I was thinking of creating issues for all the improvements here and closing it. Are you ok with that?

Yeah, thanks 👍

@kdumontnu kdumontnu closed this Jul 1, 2024
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.

4 participants