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
11ea1677
Commit
11ea1677
authored
5 years ago
by
Quentin Dufour
Committed by
Richard van der Hoff
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Limit the number of EDUs in transactions to 100 as expected by receiver (#5138)
Fixes #3951.
parent
d216a36b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/5138.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/5138.bugfix
synapse/federation/sender/per_destination_queue.py
+30
-26
30 additions, 26 deletions
synapse/federation/sender/per_destination_queue.py
synapse/storage/deviceinbox.py
+1
-1
1 addition, 1 deletion
synapse/storage/deviceinbox.py
with
32 additions
and
27 deletions
changelog.d/5138.bugfix
0 → 100644
+
1
−
0
View file @
11ea1677
Limit the number of EDUs in transactions to 100 as expected by synapse. Thanks to @superboum for this work!
This diff is collapsed.
Click to expand it.
synapse/federation/sender/per_destination_queue.py
+
30
−
26
View file @
11ea1677
...
@@ -33,6 +33,9 @@ from synapse.metrics.background_process_metrics import run_as_background_process
...
@@ -33,6 +33,9 @@ from synapse.metrics.background_process_metrics import run_as_background_process
from
synapse.storage
import
UserPresenceState
from
synapse.storage
import
UserPresenceState
from
synapse.util.retryutils
import
NotRetryingDestination
,
get_retry_limiter
from
synapse.util.retryutils
import
NotRetryingDestination
,
get_retry_limiter
# This is defined in the Matrix spec and enforced by the receiver.
MAX_EDUS_PER_TRANSACTION
=
100
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -197,7 +200,8 @@ class PerDestinationQueue(object):
...
@@ -197,7 +200,8 @@ class PerDestinationQueue(object):
pending_pdus
=
[]
pending_pdus
=
[]
while
True
:
while
True
:
device_message_edus
,
device_stream_id
,
dev_list_id
=
(
device_message_edus
,
device_stream_id
,
dev_list_id
=
(
yield
self
.
_get_new_device_messages
()
# We have to keep 2 free slots for presence and rr_edus
yield
self
.
_get_new_device_messages
(
MAX_EDUS_PER_TRANSACTION
-
2
)
)
)
# BEGIN CRITICAL SECTION
# BEGIN CRITICAL SECTION
...
@@ -216,19 +220,9 @@ class PerDestinationQueue(object):
...
@@ -216,19 +220,9 @@ class PerDestinationQueue(object):
pending_edus
=
[]
pending_edus
=
[]
pending_edus
.
extend
(
self
.
_get_rr_edus
(
force_flush
=
False
))
# We can only include at most 100 EDUs per transactions
# We can only include at most 100 EDUs per transactions
pending_edus
.
extend
(
self
.
_pop_pending_edus
(
100
-
len
(
pending_edus
)))
# rr_edus and pending_presence take at most one slot each
pending_edus
.
extend
(
self
.
_get_rr_edus
(
force_flush
=
False
))
pending_edus
.
extend
(
self
.
_pending_edus_keyed
.
values
()
)
self
.
_pending_edus_keyed
=
{}
pending_edus
.
extend
(
device_message_edus
)
pending_presence
=
self
.
_pending_presence
pending_presence
=
self
.
_pending_presence
self
.
_pending_presence
=
{}
self
.
_pending_presence
=
{}
if
pending_presence
:
if
pending_presence
:
...
@@ -248,6 +242,12 @@ class PerDestinationQueue(object):
...
@@ -248,6 +242,12 @@ class PerDestinationQueue(object):
)
)
)
)
pending_edus
.
extend
(
device_message_edus
)
pending_edus
.
extend
(
self
.
_pop_pending_edus
(
MAX_EDUS_PER_TRANSACTION
-
len
(
pending_edus
)))
while
len
(
pending_edus
)
<
MAX_EDUS_PER_TRANSACTION
and
self
.
_pending_edus_keyed
:
_
,
val
=
self
.
_pending_edus_keyed
.
popitem
()
pending_edus
.
append
(
val
)
if
pending_pdus
:
if
pending_pdus
:
logger
.
debug
(
"
TX [%s] len(pending_pdus_by_dest[dest]) = %d
"
,
logger
.
debug
(
"
TX [%s] len(pending_pdus_by_dest[dest]) = %d
"
,
self
.
_destination
,
len
(
pending_pdus
))
self
.
_destination
,
len
(
pending_pdus
))
...
@@ -259,7 +259,7 @@ class PerDestinationQueue(object):
...
@@ -259,7 +259,7 @@ class PerDestinationQueue(object):
# if we've decided to send a transaction anyway, and we have room, we
# if we've decided to send a transaction anyway, and we have room, we
# may as well send any pending RRs
# may as well send any pending RRs
if
len
(
pending_edus
)
<
100
:
if
len
(
pending_edus
)
<
MAX_EDUS_PER_TRANSACTION
:
pending_edus
.
extend
(
self
.
_get_rr_edus
(
force_flush
=
True
))
pending_edus
.
extend
(
self
.
_get_rr_edus
(
force_flush
=
True
))
# END CRITICAL SECTION
# END CRITICAL SECTION
...
@@ -346,33 +346,37 @@ class PerDestinationQueue(object):
...
@@ -346,33 +346,37 @@ class PerDestinationQueue(object):
return
pending_edus
return
pending_edus
@defer.inlineCallbacks
@defer.inlineCallbacks
def
_get_new_device_messages
(
self
):
def
_get_new_device_messages
(
self
,
limit
):
last_device_st
ream_id
=
self
.
_last_device_stream_id
last_device_
li
st
=
self
.
_last_device_
list_
stream_id
to_device_stream_id
=
self
.
_store
.
get_to_device_stream_token
()
# Will return at most 20 entries
contents
,
stream_id
=
yield
self
.
_store
.
get_
new_
device
_msgs_for
_remote
(
now_stream_id
,
results
=
yield
self
.
_store
.
get_device
s_by
_remote
(
self
.
_destination
,
last_device_st
ream_id
,
to_device_stream_id
self
.
_destination
,
last_device_
li
st
)
)
edus
=
[
edus
=
[
Edu
(
Edu
(
origin
=
self
.
_server_name
,
origin
=
self
.
_server_name
,
destination
=
self
.
_destination
,
destination
=
self
.
_destination
,
edu_type
=
"
m.d
irect_to_devic
e
"
,
edu_type
=
"
m.d
evice_list_updat
e
"
,
content
=
content
,
content
=
content
,
)
)
for
content
in
conten
ts
for
content
in
resul
ts
]
]
last_device_list
=
self
.
_last_device_list_stream_id
assert
len
(
edus
)
<=
limit
,
"
get_devices_by_remote returned too many EDUs
"
now_stream_id
,
results
=
yield
self
.
_store
.
get_devices_by_remote
(
self
.
_destination
,
last_device_list
last_device_stream_id
=
self
.
_last_device_stream_id
to_device_stream_id
=
self
.
_store
.
get_to_device_stream_token
()
contents
,
stream_id
=
yield
self
.
_store
.
get_new_device_msgs_for_remote
(
self
.
_destination
,
last_device_stream_id
,
to_device_stream_id
,
limit
-
len
(
edus
)
)
)
edus
.
extend
(
edus
.
extend
(
Edu
(
Edu
(
origin
=
self
.
_server_name
,
origin
=
self
.
_server_name
,
destination
=
self
.
_destination
,
destination
=
self
.
_destination
,
edu_type
=
"
m.d
evice_list_updat
e
"
,
edu_type
=
"
m.d
irect_to_devic
e
"
,
content
=
content
,
content
=
content
,
)
)
for
content
in
resul
ts
for
content
in
conten
ts
)
)
defer
.
returnValue
((
edus
,
stream_id
,
now_stream_id
))
defer
.
returnValue
((
edus
,
stream_id
,
now_stream_id
))
This diff is collapsed.
Click to expand it.
synapse/storage/deviceinbox.py
+
1
−
1
View file @
11ea1677
...
@@ -118,7 +118,7 @@ class DeviceInboxWorkerStore(SQLBaseStore):
...
@@ -118,7 +118,7 @@ class DeviceInboxWorkerStore(SQLBaseStore):
defer
.
returnValue
(
count
)
defer
.
returnValue
(
count
)
def
get_new_device_msgs_for_remote
(
def
get_new_device_msgs_for_remote
(
self
,
destination
,
last_stream_id
,
current_stream_id
,
limit
=
100
self
,
destination
,
last_stream_id
,
current_stream_id
,
limit
):
):
"""
"""
Args:
Args:
...
...
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