Skip to content

[9.x] Make throttle lock acquisition retry time configurable#41516

Merged
taylorotwell merged 2 commits intolaravel:9.xfrom
timmartin19:make-duration-limiter-sleep-time-configurable
Mar 16, 2022
Merged

[9.x] Make throttle lock acquisition retry time configurable#41516
taylorotwell merged 2 commits intolaravel:9.xfrom
timmartin19:make-duration-limiter-sleep-time-configurable

Conversation

@timmartin19
Copy link
Copy Markdown
Contributor

Depending on context, 750ms can be a long time to wait between retries
for a throttle. We are making the retry time configurable so that users
can tune the throttling further.

All changes are backwards compatible.

I set the unit as milliseconds because this seemed like the natural time
unit to use. Seconds would require floats which felt dirty. That being
said, it's not consistent with the unit used for ->every and ->block
on the builder. So I'm open to changing it for consistency.

I was additionally unsure what useful tests could be written for this
configuration. Mocking the usleep function felt silly. Any suggestions
are welcome.

Redis::throttle('my-key')
    ->allow(5)
    ->every(10)
    ->retryWait(100)
    ->then(static fn () => echo "hello!");

Depending on context, 750ms can be a long time to wait between retries
for a throttle.  We are making the retry time configurable so that users
can tune the throttling further.

All changes are backwards compatible.

I set the unit as milliseconds because this seemed like the natural time
unit to use.  Seconds would require floats which felt dirty.  That being
said, it's not consistent with the unit used for `->every` and `->block`
on the builder.  So I'm open to changing it for consistency.

```php
Redis::throttle('my-key')
    ->allow(5)
    ->every(10)
    ->retryWait(100)
    ->then(static fn () => echo "hello!");
```
@timmartin19 timmartin19 changed the title Make throttle lock acquisition retry time configurable [9.x] Make throttle lock acquisition retry time configurable Mar 16, 2022
@taylorotwell taylorotwell merged commit 0b4f74b into laravel:9.x Mar 16, 2022
@taylorotwell
Copy link
Copy Markdown
Member

Renamed method to sleep.

@timmartin19 timmartin19 deleted the make-duration-limiter-sleep-time-configurable branch March 16, 2022 17:02
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