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

Skip to content

feat: add debouncing to provisionerd rpc calls #5198

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 2 commits into from
Dec 1, 2022
Merged

Conversation

coadler
Copy link
Contributor

@coadler coadler commented Nov 29, 2022

coderd2 is running these changes
image

@coadler coadler force-pushed the colin/drpc-debounce branch 2 times, most recently from f786491 to 5fc0c10 Compare November 30, 2022 18:10
@coadler coadler force-pushed the colin/drpc-debounce branch from 3993cec to e3d6f9b Compare November 30, 2022 22:43
@coadler coadler marked this pull request as ready for review November 30, 2022 22:49
@coadler coadler requested a review from a team as a code owner November 30, 2022 22:49
@coadler coadler requested review from jsjoeio, kylecarbs, deansheather and a team and removed request for a team November 30, 2022 22:49
jsjoeio
jsjoeio previously approved these changes Nov 30, 2022
Copy link
Contributor

@jsjoeio jsjoeio left a comment

Choose a reason for hiding this comment

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

Not sure why it tagged me but scanned through code and nothing looks off 👍🏼

@jsjoeio jsjoeio dismissed their stale review November 30, 2022 23:01

Seems to be BE only so dismissing just to be safe it's not accidentally merged

@@ -205,8 +211,8 @@ func (p *Server) connect(ctx context.Context) {
if p.isClosed() {
return
}
ticker := time.NewTicker(p.opts.PollInterval)
defer ticker.Stop()
timer := time.NewTimer(p.opts.JobPollInterval)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to only apply this delay if it failed to acquire a job? This means we will acquire them as quick as possible without delays if there are a lot of jobs queued, but during periods of low jobs we will only attempt to acquire a job every 5 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess in theory yeah, but it's currently architected in a way where this is still ticking while the provisioner is running a job, so it'd require a bit of a refactor for this to work.

Copy link
Member

Choose a reason for hiding this comment

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

couldn't you just do something like:

for {
  ok :=acquireJob()
  if !ok {
    select {
      case <-ctx.Done():
        return ctx.Err()
      case <-time.After(5 * time.Second):
  }
}

or something? time.After's only leak if they haven't fired yet, so since the interval is small and the only time this for loop will exit is if the app is shutting down it seems fine here

Comment on lines +290 to +295
lastAcquireMutex.RLock()
if !lastAcquire.IsZero() && time.Since(lastAcquire) < p.opts.JobPollDebounce {
lastAcquireMutex.RUnlock()
return
}
lastAcquireMutex.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

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

Should disable this debounce if running in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only enabled in coder server

@coadler coadler merged commit ab3b3d5 into main Dec 1, 2022
@coadler coadler deleted the colin/drpc-debounce branch December 1, 2022 22:54
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2022
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.

3 participants