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

fix(cluster): reduce lock contention on cluster initialization #660

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

crenshaw-dev
Copy link
Member

@crenshaw-dev crenshaw-dev commented Jan 24, 2025

c.newResource calls c.populateResourceInfoHandler which, in Argo CD, may do nontrivial work: https://github.com/argoproj/argo-cd/blob/75def4f2df3e27892292b8020bfb9100a2784105/controller/cache/cache.go#L532-L560

As far as I can tell, c.newResource doesn't do any work which requires the lock.

This is the benchmark before/after:

Benchmark_sync-16    	     100	  10186413 ns/op
Benchmark_sync-16    	     212	   5531238 ns/op

Under the benchmark's conditions, cluster initialization is about twice as fast.

Tests pass in Argo CD: argoproj/argo-cd#21666

Signed-off-by: Michael Crenshaw <[email protected]>
@crenshaw-dev crenshaw-dev requested a review from a team as a code owner January 24, 2025 17:11
Copy link

Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.44%. Comparing base (8849c3f) to head (90fece3).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #660      +/-   ##
==========================================
+ Coverage   54.26%   54.44%   +0.17%     
==========================================
  Files          64       64              
  Lines        6164     6271     +107     
==========================================
+ Hits         3345     3414      +69     
- Misses       2549     2583      +34     
- Partials      270      274       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

LGTM. I dont see how this would cause a deadlock because "newResources" does not assume it has been locked and the populateResourceInfoHandler shouldnt already not perform operation on the cache that would require a lock.

@crenshaw-dev crenshaw-dev merged commit d78929e into argoproj:master Jan 24, 2025
5 checks passed
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.

3 participants