Skip to content

Commit 03056c9

Browse files
committed
Add client retry docs
1 parent 58fa778 commit 03056c9

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

.vale/Vocab/accept.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ receiveDeadline
7272
receiveTimeout
7373
sendDeadline
7474
dialTimeout
75+
backoffMultiplier
76+
disableBackoffCaps
7577
API
7678
DBA
7779
DBRE

using-gatewayd/clients.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,53 @@ You have the option to set deadlines on send and receive calls to the database s
4040
## Receive timeout
4141
4242
Since setting receive deadline kills the connection, the `receiveTimeout` property is introduced to stop the receive function from blocking the connection and waiting forever. The current value is zero, which means that it behaves like before, but one can set it to a duration string value.
43+
44+
## Dial timeout
45+
46+
The dial timeout is the amount of time the client should wait before giving up on dialing the database. The default value is `60s`. Setting it to `0s` disables the dial timeout.
47+
48+
## Retries and backoff
49+
50+
The first attempt to connect to the database server is made when the client is created, which happens instantly when GatewayD starts. However, if the first attempt fails, the client will retry the connection. The default number of retries is `3`, which means that the client will retry the connection three times before giving up. Setting it to `0` disables the retry mechanism. The client can also backoff before retrying the connection. The backoff duration is set to `1s` by default and `0s` disables the backoff mechanism. The backoff multiplier is set to `2` by default and `0` disables the backoff. The backoff multiplier is applied to the backoff duration. The backoff duration is capped at `60s` by default and the max retry is capped at `10` by default. Setting `disableBackoffCaps` to `true` disables the backoff and retry caps.
51+
52+
{: .note }
53+
> The first attempt to connect to the database server is counted as a retry, hence the three retries are actually four attempts (one instant attempt and three retry attempts), and the backoff duration is applied to the second attempt and so on.
54+
55+
The backoff duration is calculated by multiplying the backoff duration by the backoff multiplier raised to the power of the number of retries. For example, if the backoff duration is 1 second and the backoff multiplier is 2, the backoff duration will be 1 second, 2 seconds, 4 seconds, 8 seconds, etc. The backoff duration is capped at 1 minute and the backoff multiplier is capped at 10, so the backoff duration will be 1 minute after 6 retries. The backoff multiplier is capped at 10 to prevent the backoff duration from growing too quickly, unless the backoff caps are disabled. The following is the formula for calculating the backoff duration:
56+
57+
```text
58+
backoff duration = backoff * (backoff multiplier ^ current retry number)
59+
```
60+
61+
Considering the default values, the backoff duration will be calculated as follows:
62+
63+
```text
64+
1 * 2 ^ 1 = 2 seconds
65+
1 * 2 ^ 2 = 4 seconds
66+
1 * 2 ^ 3 = 8 seconds
67+
```
68+
69+
If the retries are set to `11`, the backoff duration from the fourth attempt will be calculated as follows, which is capped at 1 minute and 10 retries are made:
70+
71+
```text
72+
1 * 2 ^ 4 = 16 seconds
73+
1 * 2 ^ 5 = 32 seconds
74+
1 * 2 ^ 6 = 1 minute
75+
1 * 2 ^ 7 = 1 minute (capped)
76+
1 * 2 ^ 8 = 1 minute (capped)
77+
1 * 2 ^ 9 = 1 minute (capped)
78+
1 * 2 ^ 10 = 1 minute (capped)
79+
```
80+
81+
And if the backoff caps are disabled, the uncapped backoff duration for the fourth attempt will be calculated as follows:
82+
83+
```text
84+
1 * 2 ^ 4 = 16 seconds
85+
1 * 2 ^ 5 = 32 seconds
86+
1 * 2 ^ 6 = 1 minute 4 seconds (uncapped)
87+
1 * 2 ^ 7 = 2 minutes 8 seconds (uncapped)
88+
1 * 2 ^ 8 = 4 minutes 16 seconds (uncapped)
89+
1 * 2 ^ 9 = 8 minutes 32 seconds (uncapped)
90+
1 * 2 ^ 10 = 17 minutes 4 seconds (uncapped)
91+
1 * 2 ^ 11 = 34 minutes 8 seconds (uncapped)
92+
```

using-gatewayd/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ clients:
8383
receiveTimeout: 0s # duration, 0ms/0s means no timeout
8484
sendDeadline: 0s # duration, 0ms/0s means no deadline
8585
dialTimeout: 60s # duration, 0ms/0s means no timeout
86+
# Retry configuration
87+
retries: 3 # 0 means no retry
88+
backoff: 1s # duration
89+
backoffMultiplier: 2 # 0 means no backoff
90+
disableBackoffCaps: false
8691

8792
pools:
8893
default:

using-gatewayd/global-configuration/clients.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ GatewayD supports multiple client configurations. Each client in each configurat
2525
| receiveTimeout | duration (string) | 0s | Valid duration strings | The amount of time the client should wait before giving up on call to receive. `0s` disables receive timeout. |
2626
| sendDeadline | duration (string) | 0s | Valid duration strings | The amount of time the client should wait before giving up on call to send. `0s` disables send deadline. |
2727
| dialTimeout | duration (string) | 60s | Valid duration strings | The amount of time the client should wait before giving up on dialing the database. `0s` disables dial timeout. |
28+
| retries | number | 3 | Positive integers | The amount of times to retry a failed connection. `0` means no retry. |
29+
| backoff | duration (string) | 1s | Valid duration strings | The amount of time to wait before retrying a failed connection. `0s` means no backoff. |
30+
| backoffMultiplier | number | 2 | Positive integers | The multiplier to apply to the backoff duration. `0` means no backoff. |
31+
| disableBackoffCaps | boolean | False | True, False | Whether to disable the backoff caps for backoff multiplier and backoff duration. |
2832

2933
```yaml
3034
clients:
@@ -38,4 +42,9 @@ clients:
3842
receiveTimeout: 0s # duration, 0ms/0s means no timeout
3943
sendDeadline: 0s # duration, 0ms/0s means no deadline
4044
dialTimeout: 60s # duration, 0ms/0s means no timeout
45+
# Retry configuration
46+
retries: 3 # 0 means no retry
47+
backoff: 1s # duration
48+
backoffMultiplier: 2 # 0 means no backoff
49+
disableBackoffCaps: false
4150
```

0 commit comments

Comments
 (0)