Skip to content

Have throttled worker always wait throttleDelay between work calls#229989

Merged
lramos15 merged 8 commits intomainfrom
lramos15/encouraging-hornet
Oct 1, 2024
Merged

Have throttled worker always wait throttleDelay between work calls#229989
lramos15 merged 8 commits intomainfrom
lramos15/encouraging-hornet

Conversation

@lramos15
Copy link
Copy Markdown
Member

@lramos15 lramos15 commented Sep 27, 2024

Consider the following case, maxWorkChunkSize of 1 and a throttleDelay of 1000ms. The maxBufferedWork doesn't matter here.

  1. Queue a unit at 0ms. It immediately executes as there is nothing in the throttler
  2. Queue a unit at 500ms. It immediately executes again as there is nothing in the throttler.

This seems wrong as I don't want my work items to execute without a minimum 1000ms gap in between them. Instead even if the queue is empty, the throttled worker should ensure that the second queue task must wait 500ms before executing so it's been 1000ms since the last unit of work.

This does modify the text behavior slightly, so I am happy to make this an option on the worker options or something, but I was surprised when the worker did not work out of the box like this

@lramos15 lramos15 self-assigned this Sep 27, 2024
@lramos15 lramos15 enabled auto-merge (squash) September 27, 2024 17:34
@lramos15 lramos15 requested a review from bpasero September 27, 2024 17:35
@vs-code-engineering vs-code-engineering bot added this to the October 2024 milestone Sep 27, 2024
Comment thread src/vs/base/common/async.ts Outdated
Comment thread src/vs/base/common/async.ts Outdated
@bpasero bpasero modified the milestones: October 2024, Backlog Oct 1, 2024
@bpasero
Copy link
Copy Markdown
Member

bpasero commented Oct 1, 2024

I think this change would not be suitable for the case I created the ThrottledWorker for: if now a file watcher sends 1 event every 10ms, we would artificially wait 200ms before letting this event go. The intent was to start throttling when an unusual large number of events comes in at the same time:

private readonly throttledFileChangesEmitter = this._register(new ThrottledWorker<IFileChange>(
{
maxWorkChunkSize: 500, // only process up to 500 changes at once before...
throttleDelay: 200, // ...resting for 200ms until we process events again...
maxBufferedWork: 30000 // ...but never buffering more than 30000 events in memory
},
events => this._onDidChangeFile.fire(events)
));

@lramos15
Copy link
Copy Markdown
Member Author

lramos15 commented Oct 1, 2024

Would it be worth a throttled worker option or do you think I should just use a different utility?

Here's the PR where I try to consume this if interested. https://github.com/microsoft/vscode-copilot/pull/8758

@lramos15
Copy link
Copy Markdown
Member Author

lramos15 commented Oct 1, 2024

Update, I've made a change to put this work in IThrottledWorkerOptions

@lramos15 lramos15 requested a review from bpasero October 1, 2024 14:14
bpasero
bpasero previously approved these changes Oct 1, 2024
Copy link
Copy Markdown
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

@lramos15 yeah we can have it with that option, pushed some cleanup.

Didn't you have a test for this in your first PR?

@bpasero bpasero modified the milestones: Backlog, October 2024 Oct 1, 2024
@lramos15
Copy link
Copy Markdown
Member Author

lramos15 commented Oct 1, 2024

I did not create a test for it in my first PR because it modified the default behavior so instead I modified your existing tests. I will create a test for this and get another ✔️ since you did the cleanup. Thanks for the 💄 and review

@lramos15 lramos15 merged commit de8acda into main Oct 1, 2024
@lramos15 lramos15 deleted the lramos15/encouraging-hornet branch October 1, 2024 22:54
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Nov 15, 2024
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.

4 participants