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): reset delays after generating blockTimeout value #2529

Merged
merged 6 commits into from
Apr 21, 2024

Conversation

roggervalf
Copy link
Collaborator

@roggervalf roggervalf commented Apr 19, 2024

ref #2466

@@ -552,7 +552,7 @@ export class Worker<
try {
this.blockUntil = await this.waiting;

if (this.blockUntil <= 0 || this.blockUntil - Date.now() < 10) {
if (this.blockUntil <= 0 || this.blockUntil - Date.now() < 5) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in case this operation is too fast, what about using 5 milliseconds

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. The issue here is that if the moveToActive is called too early it may not return any job. In theory, it should be <= 1 ms to be consistent with the BZPOPMIN minimum timeout value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw I did not remember we had this hardcoded value here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's coming from b0a13e8

Copy link
Contributor

Choose a reason for hiding this comment

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

0.1 was probably a strange value, but why 5 or 10? I think the rationale here is that if the number is under a certain value, like 10ms, then the overhead may be large enough so that when calling moveToActive it will be indeed time to take the next job, but there is a possibility that this is not true in many cases and then you end calling moveToActive without doing anything, and then loop again. So probably a more correct value would be 1ms or 2ms considering our minimum value for BZPOPMIN, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I see you updated already, sorry for the long comment 😅

@@ -626,6 +626,7 @@ export class Worker<
? blockTimeout
: Math.ceil(blockTimeout);

this.updateDelays(); // reset delays to avoid reusing same values in next iteration
Copy link
Contributor

Choose a reason for hiding this comment

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

I am concerned about this. Can you express is in a test case where this was a problem before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a perf change as we can see from these logs that #2466 (comment) zpopmin is called 2 more times after consuming the last delayed marker, as the blockUntil is not reset

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, so the next call of BZPOPMIN in that example would have been the default instead of 0.9 or something.

@@ -552,7 +552,7 @@ export class Worker<
try {
this.blockUntil = await this.waiting;

if (this.blockUntil <= 0 || this.blockUntil - Date.now() < 10) {
if (this.blockUntil <= 0 || this.blockUntil - Date.now() < 5) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. The issue here is that if the moveToActive is called too early it may not return any job. In theory, it should be <= 1 ms to be consistent with the BZPOPMIN minimum timeout value.

@@ -552,7 +552,7 @@ export class Worker<
try {
this.blockUntil = await this.waiting;

if (this.blockUntil <= 0 || this.blockUntil - Date.now() < 10) {
if (this.blockUntil <= 0 || this.blockUntil - Date.now() < 5) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw I did not remember we had this hardcoded value here...

@roggervalf roggervalf changed the title fix(worker): reset delays after generating blockTimeout value perf(worker): reset delays after generating blockTimeout value Apr 20, 2024
@roggervalf roggervalf merged commit e92cea4 into master Apr 21, 2024
11 checks passed
@roggervalf roggervalf deleted the fix-reset-delays branch April 21, 2024 15:38
github-actions bot pushed a commit that referenced this pull request Apr 21, 2024
## [5.7.4](v5.7.3...v5.7.4) (2024-04-21)

### Performance Improvements

* **worker:** reset delays after generating blockTimeout value ([#2529](#2529)) ([e92cea4](e92cea4))
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