Also jitter the invalid cache period
This commit is contained in:
parent
bc5f6e1797
commit
928c50b59a
|
@ -296,16 +296,18 @@ class MatrixFederationAgent(object):
|
||||||
response = yield make_deferred_yieldable(
|
response = yield make_deferred_yieldable(
|
||||||
self._well_known_agent.request(b"GET", uri),
|
self._well_known_agent.request(b"GET", uri),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
logger.info("Connection error fetching %s: %s", uri_str, e)
|
|
||||||
self._well_known_cache.set(server_name, None, WELL_KNOWN_INVALID_CACHE_PERIOD)
|
|
||||||
defer.returnValue(None)
|
|
||||||
|
|
||||||
body = yield make_deferred_yieldable(readBody(response))
|
body = yield make_deferred_yieldable(readBody(response))
|
||||||
|
|
||||||
if response.code != 200:
|
if response.code != 200:
|
||||||
logger.info("Error response %i from %s", response.code, uri_str)
|
raise Exception("Non-200 response %s", response.code)
|
||||||
self._well_known_cache.set(server_name, None, WELL_KNOWN_INVALID_CACHE_PERIOD)
|
except Exception as e:
|
||||||
|
logger.info("Error fetching %s: %s", uri_str, e)
|
||||||
|
|
||||||
|
# add some randomness to the TTL to avoid a stampeding herd every hour
|
||||||
|
# after startup
|
||||||
|
cache_period = WELL_KNOWN_INVALID_CACHE_PERIOD
|
||||||
|
cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER)
|
||||||
|
|
||||||
|
self._well_known_cache.set(server_name, None, cache_period)
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -326,8 +328,8 @@ class MatrixFederationAgent(object):
|
||||||
)
|
)
|
||||||
if cache_period is None:
|
if cache_period is None:
|
||||||
cache_period = WELL_KNOWN_DEFAULT_CACHE_PERIOD
|
cache_period = WELL_KNOWN_DEFAULT_CACHE_PERIOD
|
||||||
# add some randomness to the TTL to avoid a stampeding herd every hour after
|
# add some randomness to the TTL to avoid a stampeding herd every 24 hours
|
||||||
# startup
|
# after startup
|
||||||
cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER)
|
cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER)
|
||||||
else:
|
else:
|
||||||
cache_period = min(cache_period, WELL_KNOWN_MAX_CACHE_PERIOD)
|
cache_period = min(cache_period, WELL_KNOWN_MAX_CACHE_PERIOD)
|
||||||
|
|
Loading…
Reference in New Issue