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

[5.5] Worker: Allow to set sleep time less than 1 seconds #22246

Merged
merged 3 commits into from Nov 29, 2017

Conversation

Projects
None yet
4 participants
@disc
Contributor

disc commented Nov 29, 2017

I'd like to set sleep time for worker less than 1 seconds, but I can't do this because we use sleep().
I suggest we can use usleep() and multiply passed $seconds to * 100000 for backward compatibility.
Now possible to pass 0.5 or 0.01 seconds

disc added some commits Nov 29, 2017

disc

@themsaid themsaid changed the title from Worker: Allow to set sleep time less than 1 seconds to [5.5] Worker: Allow to set sleep time less than 1 seconds Nov 29, 2017

@themsaid

This comment has been minimized.

Member

themsaid commented Nov 29, 2017

@disk if you sleep less than 1 second why sleep at all? Can you explain the scenario where this is useful?

@disc

This comment has been minimized.

Contributor

disc commented Nov 29, 2017

@themsaid I've got a lot of queues and i'd like to decrease sleep timeout, but don't disable it.
Small sleep timeout will produce less load than disabled option.

@taylorotwell taylorotwell merged commit 85e4c4d into laravel:5.5 Nov 29, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/styleci/pr The StyleCI analysis has passed
Details
@vlakoff

This comment has been minimized.

Contributor

vlakoff commented Nov 30, 2017

Just to point out PHP_INT_MAX is 2147483647 on 32-bit platform, so this change would break with $seconds > 2147 (about 36 minutes).

@disc

This comment has been minimized.

Contributor

disc commented Nov 30, 2017

@vlakoff I agree. I'll rewrite this code and will use usleep in case when sleep less than 1 second

@vlakoff

This comment has been minimized.

Contributor

vlakoff commented Nov 30, 2017

Alternatively, detect if value would be out of range, and when so, fallback to sleep().

@vlakoff

This comment has been minimized.

Contributor

vlakoff commented Nov 30, 2017

if (PHP_INT_SIZE < 8 && $seconds >= 2147) {
    sleep($seconds);
} else {
    usleep($seconds * 1000000);
}

This way, we reduce precision only when needed, and you can sleep 1.5 seconds :)

@disc

This comment has been minimized.

Contributor

disc commented Nov 30, 2017

Fixed in #22255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment