Skip to content

RFC: update retry plugin backoff default to be more sensible #86

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

Merged
merged 1 commit into from
Oct 16, 2017

Conversation

bendavies
Copy link
Contributor

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets #79
Documentation
License MIT

As discussed in #79, the default delay function is not very delaying at all. With 10 retries, the delays (in seconds) of the old impl are:

0.001
0.002
0.004
0.008
0.016
0.032
0.064
0.128
0.256
0.512
1.024

I've simply multiplied by 100 here, so the new delays are:

0.1
0.2
0.4
0.8
1.6
3.2
6.4
12.8
25.6
51.2
102.4

Open to other suggests for a better delay.

@Nyholm
Copy link
Member

Nyholm commented Sep 5, 2017

The documentation for the constructor says:

/**
* @var callable $delay A callback that gets a request, an exception and the number of retries 
* and returns how many milliseconds we should wait before trying again.
*/

So the callable should return milliseconds. But we use in in usleep which takes microseconds. I think we must either multiply the delay with 1000 before we use usleep or change the documentation for the callable.

@bendavies
Copy link
Contributor Author

Yep, good point. What do you think of my proposed default delay now?

@Nyholm
Copy link
Member

Nyholm commented Sep 5, 2017

I think the backoff times are more reasonable. But it would not hurt to multiply them (yours) with 5 or maybe 10. =)

@bendavies
Copy link
Contributor Author

* 5

0.005
0.01
0.02
0.04
0.08
0.16
0.32
0.64
1.28
2.56
5.12

* 10

0.01
0.02
0.04
0.08
0.16
0.32
0.64
1.28
2.56
5.12
10.24

@Nyholm
Copy link
Member

Nyholm commented Sep 5, 2017

No, sorry, I meant x500 or x1000.

@bendavies
Copy link
Contributor Author

bendavies commented Sep 5, 2017

Sure, the the relays would get very long quite quickly though:
* 500

0.5
1
2
4
8
16
32
64
128
256
512

@Nyholm
Copy link
Member

Nyholm commented Sep 5, 2017

Yeah, but doing more than 5 will rarely be necessary.

@Nyholm
Copy link
Member

Nyholm commented Sep 6, 2017

Could you make these updates to the PR? Both better defaults and the doc/multiply thing discussed?

@bendavies bendavies force-pushed the retry-plugin-backoff-default branch from 28ca08c to 5c58e4f Compare September 6, 2017 20:42
@bendavies
Copy link
Contributor Author

@Nyholm updated

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Good. Dont forget to update the tests.

@@ -117,6 +117,6 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
*/
public static function defaultDelay(RequestInterface $request, Exception $e, $retries)
{
return pow(2, $retries) * 1000;
return pow(2, $retries) * 1000 * 500;
Copy link
Member

Choose a reason for hiding this comment

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

Lets precalculate this. Write 500000 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually did this intentionally so it's more obvious what we are doing, but happy to oblige .

@bendavies bendavies force-pushed the retry-plugin-backoff-default branch from 5c58e4f to f1990f9 Compare September 6, 2017 22:27
@bendavies
Copy link
Contributor Author

spec updated

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you.

@joelwurtz joelwurtz merged commit 040d632 into php-http:master Oct 16, 2017
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.

3 participants