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

Use exponential backoff with jitter #2419

Merged
merged 5 commits into from
Apr 14, 2023

Conversation

j0holo
Copy link
Contributor

@j0holo j0holo commented Apr 12, 2023

Description

Closes #1720.

I have added ctxutil.SleepWithJitter based on https://aws.amazon.com/ru/blogs/architecture/exponential-backoff-and-jitter/ (FullJitter).

I did not complete all tasks in the issue for the following reason:

  • time.Sleep is not used
  • context.WithTimeout is only used for actual timeout from what I'm reading. It does not make sense to add jitter to context timeouts if FerretDB does not retry something based on the context timing out.
  • ctxutil.Sleep has been replaced with a version that adds jitter with one exception: reporter.Run has a reportInternal duration that has no need for jitter.
  • All other ctxutil.Sleeps where located in for loops where the intention is clear that FerretDB is retrying some task. Adding jitter makes sense in these cases.

For the three unit tests I have added I had difficulty with making sure my tests are correct because SleepWithJitter uses rand.Int63n which makes it difficult to validate testing boundaries.

Readiness checklist

  • I added/updated unit tests.
  • I added/updated integration/compatibility tests.
  • I added/updated comments and checked rendering.
  • I made spot refactorings.
  • I updated user documentation.
  • I ran task all, and it passed. <-- returns package.txt: open package.txt: no such file or directory
  • I ensured that PR title is good enough for the changelog.
  • (for maintainers only) I set Reviewers (@FerretDB/core), Assignee, Labels, Project and project's Sprint fields.
  • I marked all done items in this checklist.

@j0holo j0holo requested a review from a team as a code owner April 12, 2023 20:25
@CLAassistant
Copy link

CLAassistant commented Apr 12, 2023

CLA assistant check
All committers have signed the CLA.

@AlekSi AlekSi enabled auto-merge (squash) April 12, 2023 20:29
@AlekSi AlekSi added the code/chore Code maintenance improvements label Apr 12, 2023
@AlekSi AlekSi added this to the v1.1.0 milestone Apr 12, 2023
auto-merge was automatically disabled April 12, 2023 20:31

Head branch was pushed to by a user without write access

@j0holo j0holo force-pushed the exponential-backoff-with-jitter branch from 531bd4c to 5065b5a Compare April 12, 2023 20:31
@AlekSi AlekSi requested review from a team and noisersup April 12, 2023 20:31
@AlekSi
Copy link
Member

AlekSi commented Apr 12, 2023

@j0holo could you please squash your commits so there is only one with a email address that matches your GitHub email address?

@j0holo j0holo force-pushed the exponential-backoff-with-jitter branch from 5065b5a to 5653b38 Compare April 12, 2023 20:36
@codecov
Copy link

codecov bot commented Apr 12, 2023

Codecov Report

Merging #2419 (05a39a1) into main (486709f) will decrease coverage by 37.42%.
The diff coverage is 85.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2419       +/-   ##
===========================================
- Coverage   64.32%   26.91%   -37.42%     
===========================================
  Files         392      392               
  Lines       19234    19251       +17     
===========================================
- Hits        12373     5182     -7191     
- Misses       5962    13514     +7552     
+ Partials      899      555      -344     
Impacted Files Coverage Δ
internal/handlers/tigris/tigrisdb/databases.go 53.70% <0.00%> (ø)
internal/clientconn/listener.go 54.35% <33.33%> (-18.70%) ⬇️
internal/handlers/pg/pgdb/transactions.go 70.12% <100.00%> (-2.60%) ⬇️
internal/util/ctxutil/ctxutil.go 41.66% <100.00%> (-39.29%) ⬇️

... and 122 files with indirect coverage changes

Flag Coverage Δ
integration 4.72% <0.00%> (-52.65%) ⬇️
mongodb 4.72% <0.00%> (-0.01%) ⬇️
pg ?
unit 25.57% <85.00%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@j0holo j0holo force-pushed the exponential-backoff-with-jitter branch 3 times, most recently from ad1fde5 to c2d9d1d Compare April 12, 2023 20:45
@j0holo
Copy link
Contributor Author

j0holo commented Apr 12, 2023

@j0holo could you please squash your commits so there is only one with a email address that matches your GitHub email address?

Yeah, I already saw that problem. Fixed it now.

Copy link
Member

@chilagrow chilagrow left a comment

Choose a reason for hiding this comment

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

Thanks for contributing! I have a few suggestions 🤗

cmd/envtool/envtool.go Outdated Show resolved Hide resolved
internal/util/ctxutil/ctxutil.go Outdated Show resolved Hide resolved
internal/handlers/pg/pgdb/transactions.go Outdated Show resolved Hide resolved
internal/handlers/tigris/tigrisdb/databases.go Outdated Show resolved Hide resolved
@AlekSi AlekSi enabled auto-merge (squash) April 13, 2023 12:35
@AlekSi AlekSi changed the title Exponential backoff with jitter Use exponential backoff with jitter Apr 13, 2023
@AlekSi AlekSi removed their request for review April 13, 2023 12:35
auto-merge was automatically disabled April 13, 2023 15:43

Head branch was pushed to by a user without write access

@j0holo j0holo force-pushed the exponential-backoff-with-jitter branch from c2d9d1d to 4681e54 Compare April 13, 2023 15:43
@j0holo j0holo force-pushed the exponential-backoff-with-jitter branch from 4681e54 to c8a27b6 Compare April 13, 2023 15:59
@AlekSi
Copy link
Member

AlekSi commented Apr 13, 2023

@j0holo Assuming that your git configuration includes email address now, please don't squash and force-push your commits anymore – we are squashing them on PR merge anyway, but that makes reviews harder.

@w84thesun PTAL

@AlekSi AlekSi requested a review from chilagrow April 13, 2023 16:39
@AlekSi
Copy link
Member

AlekSi commented Apr 13, 2023

package.txt: open package.txt: no such file or directory

That's not an error, just a bit confusing message. I will fix it in another PR

@AlekSi AlekSi enabled auto-merge (squash) April 13, 2023 16:41
@AlekSi
Copy link
Member

AlekSi commented Apr 13, 2023

@j0holo Please reformat your code with task fmt. We use https://github.com/mvdan/gofumpt that is a bit more opinionated than go fmt

w84thesun
w84thesun previously approved these changes Apr 13, 2023
Copy link
Contributor

@w84thesun w84thesun left a comment

Choose a reason for hiding this comment

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

Changes look reasonable to me! Let's fix the linter complaints and merge this!

auto-merge was automatically disabled April 13, 2023 17:25

Head branch was pushed to by a user without write access

@j0holo
Copy link
Contributor Author

j0holo commented Apr 13, 2023

@j0holo Assuming that your git configuration includes email address now, please don't squash and force-push your commits anymore – we are squashing them on PR merge anyway, but that makes reviews harder.

I figured because I had to squash my changes in the beginning and because nothing is noted about in the contribution guide.

@AlekSi
Copy link
Member

AlekSi commented Apr 13, 2023

It is documented here – that's our extra guidelines for advanced contributors. :) But yeah, I think we could move a part of it to CONTRIBUTING.md

@AlekSi AlekSi requested a review from w84thesun April 13, 2023 17:31
@AlekSi AlekSi enabled auto-merge (squash) April 13, 2023 17:31
@j0holo
Copy link
Contributor Author

j0holo commented Apr 13, 2023

I see, it would help for new contributors to do the right thing at once.

@AlekSi
Copy link
Member

AlekSi commented Apr 13, 2023

Created #2427

Copy link
Member

@chilagrow chilagrow left a comment

Choose a reason for hiding this comment

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

🚀

@AlekSi AlekSi merged commit 12342c7 into FerretDB:main Apr 14, 2023
fenogentov pushed a commit to fenogentov/FerretDB that referenced this pull request Apr 17, 2023
fenogentov pushed a commit to fenogentov/FerretDB that referenced this pull request Apr 20, 2023
fenogentov pushed a commit to fenogentov/FerretDB that referenced this pull request Apr 20, 2023
fenogentov pushed a commit to fenogentov/FerretDB that referenced this pull request Apr 20, 2023
fenogentov pushed a commit to fenogentov/FerretDB that referenced this pull request Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/chore Code maintenance improvements
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Use exponential backoff with jitter
5 participants