Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: increase fileCache hit rate in autobuilds lifecycle #18507

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
merged 1 commit into from
Jun 24, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jun 23, 2025

wsbuilder hits the file cache when running validation. This solution is imperfect, but by first sorting workspaces by their template version id, the cache hit rate should improve.

If there is a large number of workspaces, this could save some memory impact of dynamic parameters.

Future Work

A lot of builds have overlapping queries to fetch template information:

  • tx.GetTemplateByID
  • GetTemplateVersionByID

We could also cache these between the go routines running the builds to reduce some db load.

Copy link
Member Author

Emyrk commented Jun 23, 2025

Comment on lines 78 to 79
Help: "The total number of file references ever opened in the file cache. The label 'hit' indicates whether the file was already in the cache ('true') or not ('false').",
}, []string{"hit"})
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 a label for detecting our cache hit rate

@Emyrk Emyrk changed the base branch from stevenmasley/dynamic_validate to graphite-base/18507 June 23, 2025 16:11
@Emyrk Emyrk force-pushed the graphite-base/18507 branch from 4f52076 to c1d05a0 Compare June 23, 2025 16:46
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from d73e843 to ae40278 Compare June 23, 2025 16:46
@Emyrk Emyrk changed the base branch from graphite-base/18507 to stevenmasley/dynamic_validate June 23, 2025 16:46
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from ae40278 to a4c0df4 Compare June 23, 2025 16:55
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_validate branch from c1d05a0 to 129235b Compare June 23, 2025 16:59
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from a4c0df4 to a97fd53 Compare June 23, 2025 17:00
@Emyrk Emyrk changed the base branch from stevenmasley/dynamic_validate to graphite-base/18507 June 23, 2025 17:04
@Emyrk Emyrk force-pushed the graphite-base/18507 branch from 129235b to 82af2e0 Compare June 23, 2025 17:36
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from a97fd53 to 9945049 Compare June 23, 2025 17:36
@Emyrk Emyrk changed the base branch from graphite-base/18507 to main June 23, 2025 17:36
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from 9945049 to e5a33c1 Compare June 23, 2025 17:36
@Emyrk Emyrk requested a review from aslilac June 23, 2025 17:38
@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from e5a33c1 to 4f6244f Compare June 23, 2025 17:43
Comment on lines +164 to +171
// `wsbuilder` needs to load the terraform files for a given template version
// into memory. If 2 workspaces are using the same template version, they will
// share the same files in the FileCache. This only happens if the builds happen
// in parallel.
// TODO: Actually make sure the cache has the files in the cache for the full
// set of identical template versions. Then unload the files when the builds
// are done. Right now, this relies on luck for the 10 goroutine workers to
// overlap and keep the file reference in the cache alive.
Copy link
Member

Choose a reason for hiding this comment

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

yeah, it could be nice if we did more of a "mark and sweep" style release strategy. or maybe generational...

oh no, am I about to build a general purpose garbage collector for this? Oh No

Copy link
Member Author

@Emyrk Emyrk Jun 23, 2025

Choose a reason for hiding this comment

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

Yea, I had a similar set of thoughts and decided this was a good enough idea for this release.

There is a better way to do this for sure, and I wonder where else in the codebase we will have similar things going on (prebuilds?). That being a large set of workspaces that have some work to be done in bulk.

@Emyrk Emyrk force-pushed the stevenmasley/dynamic_auto_build_optimization branch from 4f6244f to bc38b64 Compare June 23, 2025 22:13
@Emyrk Emyrk merged commit 7b152cd into main Jun 24, 2025
35 checks passed
@Emyrk Emyrk deleted the stevenmasley/dynamic_auto_build_optimization branch June 24, 2025 12:36
@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants