Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
1dec3156
Commit
1dec3156
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Change jitter to be a factor rather than absolute value
parent
861d663c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/http/federation/well_known_resolver.py
+12
-11
12 additions, 11 deletions
synapse/http/federation/well_known_resolver.py
tests/http/federation/test_matrix_federation_agent.py
+2
-2
2 additions, 2 deletions
tests/http/federation/test_matrix_federation_agent.py
with
14 additions
and
13 deletions
synapse/http/federation/well_known_resolver.py
+
12
−
11
View file @
1dec3156
...
@@ -32,8 +32,8 @@ from synapse.util.metrics import Measure
...
@@ -32,8 +32,8 @@ from synapse.util.metrics import Measure
# period to cache .well-known results for by default
# period to cache .well-known results for by default
WELL_KNOWN_DEFAULT_CACHE_PERIOD
=
24
*
3600
WELL_KNOWN_DEFAULT_CACHE_PERIOD
=
24
*
3600
# jitter to add to the .well-known default cache ttl
# jitter
factor
to add to the .well-known default cache ttl
s
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
=
10
*
60
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
=
0.1
# period to cache failure to fetch .well-known for
# period to cache failure to fetch .well-known for
WELL_KNOWN_INVALID_CACHE_PERIOD
=
1
*
3600
WELL_KNOWN_INVALID_CACHE_PERIOD
=
1
*
3600
...
@@ -133,16 +133,14 @@ class WellKnownResolver(object):
...
@@ -133,16 +133,14 @@ class WellKnownResolver(object):
# We have recently seen a valid well-known record for this
# We have recently seen a valid well-known record for this
# server, so we cache the lack of well-known for a shorter time.
# server, so we cache the lack of well-known for a shorter time.
cache_period
=
WELL_KNOWN_DOWN_CACHE_PERIOD
cache_period
=
WELL_KNOWN_DOWN_CACHE_PERIOD
cache_period
+=
random
.
uniform
(
0
,
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
)
else
:
else
:
# add some randomness to the TTL to avoid a stampeding herd every hour
# after startup
cache_period
=
WELL_KNOWN_INVALID_CACHE_PERIOD
cache_period
=
WELL_KNOWN_INVALID_CACHE_PERIOD
cache_period
+=
random
.
uniform
(
0
,
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
# add some randomness to the TTL to avoid a stampeding herd
)
cache_period
*=
random
.
uniform
(
1
-
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
,
1
+
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
,
)
if
cache_period
>
0
:
if
cache_period
>
0
:
self
.
_well_known_cache
.
set
(
server_name
,
result
,
cache_period
)
self
.
_well_known_cache
.
set
(
server_name
,
result
,
cache_period
)
...
@@ -194,7 +192,10 @@ class WellKnownResolver(object):
...
@@ -194,7 +192,10 @@ class WellKnownResolver(object):
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 24 hours
# add some randomness to the TTL to avoid a stampeding herd every 24 hours
# after startup
# after startup
cache_period
+=
random
.
uniform
(
0
,
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
)
cache_period
*=
random
.
uniform
(
1
-
WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER
,
1
+
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
)
cache_period
=
max
(
cache_period
,
WELL_KNOWN_MIN_CACHE_PERIOD
)
cache_period
=
max
(
cache_period
,
WELL_KNOWN_MIN_CACHE_PERIOD
)
...
...
This diff is collapsed.
Click to expand it.
tests/http/federation/test_matrix_federation_agent.py
+
2
−
2
View file @
1dec3156
...
@@ -551,7 +551,7 @@ class MatrixFederationAgentTests(TestCase):
...
@@ -551,7 +551,7 @@ class MatrixFederationAgentTests(TestCase):
self
.
assertEqual
(
self
.
well_known_cache
[
b
"
testserv
"
],
b
"
target-server
"
)
self
.
assertEqual
(
self
.
well_known_cache
[
b
"
testserv
"
],
b
"
target-server
"
)
# check the cache expires
# check the cache expires
self
.
reactor
.
pump
((
25
*
3600
,))
self
.
reactor
.
pump
((
48
*
3600
,))
self
.
well_known_cache
.
expire
()
self
.
well_known_cache
.
expire
()
self
.
assertNotIn
(
b
"
testserv
"
,
self
.
well_known_cache
)
self
.
assertNotIn
(
b
"
testserv
"
,
self
.
well_known_cache
)
...
@@ -639,7 +639,7 @@ class MatrixFederationAgentTests(TestCase):
...
@@ -639,7 +639,7 @@ class MatrixFederationAgentTests(TestCase):
self
.
assertEqual
(
self
.
well_known_cache
[
b
"
testserv
"
],
b
"
target-server
"
)
self
.
assertEqual
(
self
.
well_known_cache
[
b
"
testserv
"
],
b
"
target-server
"
)
# check the cache expires
# check the cache expires
self
.
reactor
.
pump
((
25
*
3600
,))
self
.
reactor
.
pump
((
48
*
3600
,))
self
.
well_known_cache
.
expire
()
self
.
well_known_cache
.
expire
()
self
.
assertNotIn
(
b
"
testserv
"
,
self
.
well_known_cache
)
self
.
assertNotIn
(
b
"
testserv
"
,
self
.
well_known_cache
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment