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

Replace GraphMap’s map with a moka::sync::Cache #1224

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

chirino
Copy link
Contributor

@chirino chirino commented Jan 31, 2025

Fixes issue #1218

@chirino
Copy link
Contributor Author

chirino commented Jan 31, 2025

We should add some tests around the cache eviction edge cases:

  • Verify old sboms are dropped as the cache fills
  • Find out what happens when the cache is smaller a single request requires.

This is needed since the graph map may evict an entry after it’s loaded.  This allows
The request to hold onto all the graphs need to process the current request.

Signed-off-by: Hiram Chirino <[email protected]>
Comment on lines +44 to +66
pub(crate) fn set_approximate_memory_size(&self) -> PackageNode {
// Is there a better way to do this?
let size = size_of::<PackageNode>()
+ self.sbom_id.len()
+ self.node_id.len()
+ self.purl.iter().fold(0, |acc, purl|
// use the json string length as an approximation of the memory size
acc + serde_json::to_string(purl).unwrap_or_else(|_| "".to_string()).len())
+ self.cpe.iter().fold(0, |acc, cpe|
// use the json string length as an approximation of the memory size
acc + serde_json::to_string(cpe).unwrap_or_else(|_| "".to_string()).len())
+ self.name.len()
+ self.version.len()
+ self.published.len()
+ self.document_id.len()
+ self.product_name.len()
+ self.product_version.len();

PackageNode {
approximate_memory_size: size.try_into().unwrap_or(u32::MAX),
..self.clone()
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to estimate how much memory this thing uses up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kinda assuming that saving the approximate_memory_size will give us savings later, it might not.

This allows test results to be consistent.

Signed-off-by: Hiram Chirino <[email protected]>
@chirino
Copy link
Contributor Author

chirino commented Jan 31, 2025

@JimFuller-RedHat I think I'm happy with this now. I'm going to keep it draft until #1217 goes in so you guys don't suffer the conflicts. But if you have idle time maybe worth a gander in case you think this went in the wrong direction.

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.

1 participant