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

perf(worker.ts): lowering the threshold at which blocking redis operation is used to fetch next job #2450

Closed

Conversation

urossmolnik
Copy link

With constant delayed jobs in highly used queue (mostly processing at least one job all the time), it can happen calculated blockTimeout is mostly smaller then current hardcoded threshold of 50ms.

If this happens, worker run loop ends up looping with no awaits, causing high CPU usage on Redis and runtime itself.

Lowering default to 10ms solved the problem for our use case. This PR also exposes this setting as advanced setting if further tweaks are needed.

…tion is used to fetch next job

With constant delayed jobs in highly used queue (mostly processing at least one job), it can happen
calculated `blockTimeout` is mostly smaller then current hardcoded threashold of 50ms.

If this happens, worker run loop ends up looping with no awaits, causing high CPU usage on Redis
and runtime itself.
@manast
Copy link
Contributor

manast commented Feb 26, 2024

Thanks for the PR. Before merging I will make some analysis to why this improves your case. Blocking for 10ms seems like it should not have a lot of effect considering the overhead of issuing a blocking command for such a little amount of time, but as mentioned, I will try to fully understand why it helps in your case and see if there is a better solution.

@urossmolnik
Copy link
Author

urossmolnik commented Feb 26, 2024

@manast thanks. Just do add, this did significantly improve our use case (about half less calls to Redis).
We do still have quite high number of calls to Redis and it does seem like only every 10th fetch call actually returns the job. So I am sure a better solution exists 🤔

@manast
Copy link
Contributor

manast commented Feb 27, 2024

@urossmolnik did you try with a blocking value less than 10ms? or even blocking as long as it is a positive number?

@urossmolnik
Copy link
Author

@urossmolnik did you try with a blocking value less than 10ms? or even blocking as long as it is a positive number?

@manast we did try with 5ms. But that did not make any difference. We can try today going down to 1ms and see.

Could the cause just be that every worker gets same timeout. So just one worker will get the job and the rest will just end up fetching empty job?

@manast
Copy link
Contributor

manast commented Feb 27, 2024

If you have several instances of workers, then it is unavoidable that if you do not have the "pipe" of jobs waiting to be processed full, that some workers will try to fetch and get empty. But for 1 worker, independently of the concurrency it should not fetch empty more than once every drain delay or something like that.

@urossmolnik
Copy link
Author

Going down and executing blocking query as soon as blockTimeout > 0, did get us another 15% less commands executed on Redis.
We did also followed up today and round delay's to seconds. Wondering if this can help with blockUntil calculations? 🤔

@roggervalf roggervalf closed this in 2de15ca Mar 1, 2024
github-actions bot pushed a commit that referenced this pull request Mar 1, 2024
## [5.4.1](v5.4.0...v5.4.1) (2024-03-01)

### Bug Fixes

* **worker:** set blockTimeout as 0.001 when reach the time to get delayed jobs ([#2455](#2455)) fixes [#2450](#2450) ([2de15ca](2de15ca))
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.

2 participants