Skip to content

Commit dd8f0d6

Browse files
authored
Retry Connect with Exponential Backoff (#12397)
1 parent a703484 commit dd8f0d6

14 files changed

Lines changed: 57 additions & 1 deletion

File tree

doc/admin-guide/files/records.yaml.en.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,14 @@ Origin Server Connect Attempts
17051705
`proxy.config.http.connect_attempts_max_retries`_ so an error is returned to the client faster and also to reduce the load on the down origin.
17061706
The timeout interval `proxy.config.http.connect_attempts_timeout`_ in seconds is used with this setting.
17071707

1708+
.. ts:cv:: CONFIG proxy.config.http.connect_attempts_retry_backoff_base INT 0
1709+
:reloadable:
1710+
:overridable:
1711+
:units: milliseconds
1712+
1713+
The base delay, in milliseconds, used for exponential backoff between retry attempts to connect to the origin server. After each
1714+
failure the delay doubles - e.g. 64m, 128m, 256m. When this is set to `0` (the default value), |TS| retries immediately without exponential backoff.
1715+
17081716
.. ts:cv:: CONFIG proxy.config.http.connect.down.policy INT 2
17091717
:overridable:
17101718

doc/developer-guide/api/functions/TSHttpOverridableConfig.en.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ TSOverridableConfigKey Value Config
118118
:enumerator:`TS_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES` :ts:cv:`proxy.config.http.connect_attempts_max_retries`
119119
:enumerator:`TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES` :ts:cv:`proxy.config.http.connect_attempts_rr_retries`
120120
:enumerator:`TS_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT` :ts:cv:`proxy.config.http.connect_attempts_timeout`
121+
:enumerator:`TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE` :ts:cv:`proxy.config.http.connect_attempts_retry_backoff_base`
121122
:enumerator:`TS_CONFIG_HTTP_DEFAULT_BUFFER_SIZE` :ts:cv:`proxy.config.http.default_buffer_size`
122123
:enumerator:`TS_CONFIG_HTTP_DEFAULT_BUFFER_WATER_MARK` :ts:cv:`proxy.config.http.default_buffer_water_mark`
123124
:enumerator:`TS_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS` :ts:cv:`proxy.config.http.doc_in_cache_skip_dns`

doc/developer-guide/api/types/TSOverridableConfigKey.en.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Enumeration Members
8181
.. enumerator:: TS_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES_DOWN_SERVER
8282
.. enumerator:: TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES
8383
.. enumerator:: TS_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT
84+
.. enumerator:: TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE
8485
.. enumerator:: TS_CONFIG_HTTP_POST_CONNECT_ATTEMPTS_TIMEOUT
8586
.. enumerator:: TS_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME
8687
.. enumerator:: TS_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS

include/proxy/http/HttpConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ struct OverridableHttpConfigParams {
660660
MgmtInt connect_attempts_max_retries_down_server = 3;
661661
MgmtInt connect_attempts_rr_retries = 3;
662662
MgmtInt connect_attempts_timeout = 30;
663+
MgmtInt connect_attempts_retry_backoff_base = 0;
663664

664665
MgmtInt connect_down_policy = 2;
665666

include/proxy/http/HttpSM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
#define CONNECT_EVENT_TXN (HTTP_NET_CONNECTION_EVENT_EVENTS_START) + 0
6060
#define CONNECT_EVENT_DIRECT (HTTP_NET_CONNECTION_EVENT_EVENTS_START) + 1
61+
#define CONNECT_EVENT_RETRY (HTTP_NET_CONNECTION_EVENT_EVENTS_START) + 2
6162

6263
// The default size for http header buffers when we don't
6364
// need to include extra space for the document

include/ts/apidefs.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ enum TSOverridableConfigKey {
821821
TS_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES_DOWN_SERVER,
822822
TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES,
823823
TS_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT,
824+
TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE,
824825
TS_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME,
825826
TS_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS,
826827
TS_CONFIG_HTTP_BACKGROUND_FILL_ACTIVE_TIMEOUT,

plugins/lua/ts_lua_http_config.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef enum {
7474
TS_LUA_CONFIG_HTTP_CONNECT_DOWN_POLICY = TS_CONFIG_HTTP_CONNECT_DOWN_POLICY,
7575
TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES = TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES,
7676
TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT = TS_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT,
77+
TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE = TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE,
7778
TS_LUA_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME = TS_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME,
7879
TS_LUA_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS = TS_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS,
7980
TS_LUA_CONFIG_HTTP_BACKGROUND_FILL_ACTIVE_TIMEOUT = TS_CONFIG_HTTP_BACKGROUND_FILL_ACTIVE_TIMEOUT,
@@ -215,6 +216,7 @@ ts_lua_var_item ts_lua_http_config_vars[] = {
215216
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_CONNECT_DOWN_POLICY),
216217
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES),
217218
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT),
219+
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE),
218220
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME),
219221
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS),
220222
TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_HTTP_BACKGROUND_FILL_ACTIVE_TIMEOUT),

src/api/InkAPI.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7259,6 +7259,9 @@ _conf_to_memberp(TSOverridableConfigKey conf, OverridableHttpConfigParams *overr
72597259
case TS_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT:
72607260
ret = _memberp_to_generic(&overridableHttpConfig->connect_attempts_timeout, conv);
72617261
break;
7262+
case TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RETRY_BACKOFF_BASE:
7263+
ret = _memberp_to_generic(&overridableHttpConfig->connect_attempts_retry_backoff_base, conv);
7264+
break;
72627265
case TS_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME:
72637266
conv = &HttpDownServerCacheTimeConv;
72647267
ret = &overridableHttpConfig->down_server_timeout;

src/api/InkAPITest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8704,6 +8704,7 @@ std::array<std::string_view, TS_CONFIG_LAST_ENTRY> SDK_Overridable_Configs = {
87048704
"proxy.config.http.connect_attempts_max_retries_down_server",
87058705
"proxy.config.http.connect_attempts_rr_retries",
87068706
"proxy.config.http.connect_attempts_timeout",
8707+
"proxy.config.http.connect_attempts_retry_backoff_base",
87078708
"proxy.config.http.down_server.cache_time",
87088709
"proxy.config.http.doc_in_cache_skip_dns",
87098710
"proxy.config.http.background_fill_active_timeout",

src/proxy/http/HttpConfig.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,8 @@ HttpConfig::startup()
878878
HttpEstablishStaticConfigLongLong(c.oride.connect_attempts_max_retries, "proxy.config.http.connect_attempts_max_retries");
879879
HttpEstablishStaticConfigLongLong(c.oride.connect_attempts_max_retries_down_server,
880880
"proxy.config.http.connect_attempts_max_retries_down_server");
881+
HttpEstablishStaticConfigLongLong(c.oride.connect_attempts_retry_backoff_base,
882+
"proxy.config.http.connect_attempts_retry_backoff_base");
881883

882884
HttpEstablishStaticConfigLongLong(c.oride.connect_down_policy, "proxy.config.http.connect.down.policy");
883885

@@ -1173,6 +1175,8 @@ HttpConfig::reconfigure()
11731175
"will never redispatch to another server",
11741176
m_master.oride.connect_attempts_rr_retries, params->oride.connect_attempts_max_retries);
11751177
}
1178+
params->oride.connect_attempts_retry_backoff_base = m_master.oride.connect_attempts_retry_backoff_base;
1179+
11761180
params->oride.connect_attempts_rr_retries = m_master.oride.connect_attempts_rr_retries;
11771181
params->oride.connect_attempts_timeout = m_master.oride.connect_attempts_timeout;
11781182
params->oride.connect_down_policy = m_master.oride.connect_down_policy;

0 commit comments

Comments
 (0)