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

feat(reposerver): Skip calling git fetch if commit to checkout exists locally #18657

Conversation

shady-canva
Copy link
Contributor

@shady-canva shady-canva commented Jun 14, 2024

Problem

Our monorepo is frequently updated with hundreds of application changes in a very short period of time (within 15 to 30 minutes). This leads to a large amount of calls to checkoutRevision in the reposerver, where git fetch is called each time. Since checkoutRevision is wrapped in a lock, it becomes a bottleneck that causes the application controller's work-queue depth to blow up:

image

Solution

When we have a lot of commits landing around the same time, chances are a previous git fetch would have already pulled in the commit SHA we want to checkout. Therefore, this PR introduces a check to see if the revision being checked out already exists locally. If so, git fetch is skipped and we move on directly to git checkout.

Outcome

Decreased git fetch calls

We've had this change deployed in production for a month now, and so far we've seen an 80% decrease in git fetch calls. Over a two week period, we ended up skipping 134,000 calls we would have otherwise made:

image

Decreased work-queue depth

Our application-controller has been a lot healthier since we made this change. During most peak periods, we only see a work-queue depth in the single digits now. Previously we were dealing with a depth exceeding 400.

image

Decreased sync times

Our application sync durations are now steady and predictable, usually in the range of 20 to 30 seconds, no matter the load. Prior to the change, we were dealing with sync durations in the 5 to 10 minute range.

image

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@shady-canva shady-canva requested a review from a team as a code owner June 14, 2024 05:41
Signed-off-by: Shady Rafehi <shady@canva.com>
Signed-off-by: Shady Rafehi <shady@canva.com>
Signed-off-by: Shady Rafehi <shady@canva.com>
Signed-off-by: Shady Rafehi <shady@canva.com>
@shady-canva shady-canva force-pushed the shady/211-skip-git-fetch-if-revision-present branch from af3eef6 to 566ea73 Compare June 14, 2024 06:12
Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 9 lines in your changes missing coverage. Please review.

Project coverage is 47.58%. Comparing base (9f1e2e8) to head (6ec03b8).
Report is 521 commits behind head on master.

Files with missing lines Patch % Lines
util/git/mocks/Client.go 50.00% 2 Missing and 3 partials ⚠️
reposerver/repository/repository.go 75.00% 1 Missing and 1 partial ⚠️
util/git/client.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #18657      +/-   ##
==========================================
+ Coverage   47.56%   47.58%   +0.01%     
==========================================
  Files         332      332              
  Lines       46746    46771      +25     
==========================================
+ Hits        22236    22256      +20     
  Misses      21665    21665              
- Partials     2845     2850       +5     

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

reposerver/repository/repository.go Outdated Show resolved Hide resolved
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Shady Rafehi <shady@canva.com>
Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

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

Thanks @shady-canva. The change LGTM 🚀
@crenshaw-dev do you have any other concerns?

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

lgtm, let's see how it behaves!

@crenshaw-dev crenshaw-dev merged commit 336cc29 into argoproj:master Jun 15, 2024
28 checks passed
@christianh814
Copy link
Member

Awesome, thanks for this!

@jenting
Copy link
Contributor

jenting commented Jun 16, 2024

Awesome 👏

Will this backport to the previous versions?

Hariharasuthan99 pushed a commit to AmadeusITGroup/argo-cd that referenced this pull request Jun 16, 2024
… locally (argoproj#18657)

* Skip fetch if revision to check out exists locally

Signed-off-by: Shady Rafehi <shady@canva.com>

* Test reposerver/repository.checkoutRevision

Signed-off-by: Shady Rafehi <shady@canva.com>

* Test client.IsRevisionPresent

Signed-off-by: Shady Rafehi <shady@canva.com>

* Signoff

Signed-off-by: Shady Rafehi <shady@canva.com>

* Update reposerver/repository/repository.go

Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Shady Rafehi <shady@canva.com>

---------

Signed-off-by: Shady Rafehi <shady@canva.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
@blakeromano
Copy link

This is much appreciated! 🙌

@bouchrihamomo
Copy link

thanks for this 🙌

ggjulio pushed a commit to ggjulio/argo-cd that referenced this pull request Jul 21, 2024
… locally (argoproj#18657)

* Skip fetch if revision to check out exists locally

Signed-off-by: Shady Rafehi <shady@canva.com>

* Test reposerver/repository.checkoutRevision

Signed-off-by: Shady Rafehi <shady@canva.com>

* Test client.IsRevisionPresent

Signed-off-by: Shady Rafehi <shady@canva.com>

* Signoff

Signed-off-by: Shady Rafehi <shady@canva.com>

* Update reposerver/repository/repository.go

Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Shady Rafehi <shady@canva.com>

---------

Signed-off-by: Shady Rafehi <shady@canva.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
jsolana pushed a commit to jsolana/argo-cd that referenced this pull request Jul 24, 2024
… locally (argoproj#18657)

* Skip fetch if revision to check out exists locally

Signed-off-by: Shady Rafehi <shady@canva.com>

* Test reposerver/repository.checkoutRevision

Signed-off-by: Shady Rafehi <shady@canva.com>

* Test client.IsRevisionPresent

Signed-off-by: Shady Rafehi <shady@canva.com>

* Signoff

Signed-off-by: Shady Rafehi <shady@canva.com>

* Update reposerver/repository/repository.go

Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Shady Rafehi <shady@canva.com>

---------

Signed-off-by: Shady Rafehi <shady@canva.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Javier Solana <javier.solana@cabify.com>
Signed-off-by: Javier Solana <javier.solana@cabify.com>
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.

7 participants