Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Send federation events concurrently #3078

Merged
merged 6 commits into from
Apr 10, 2018
Merged

Conversation

erikjohnston
Copy link
Member

This also cherry-picks Handle exceptions in get_hosts_for_room... from matrix-org-hotfixes

@@ -207,6 +213,19 @@ def _process_event_queue_loop(self):

self._send_pdu(event, destinations)

def handle_room_events(events):
for event in events:
return handle_event(event)
Copy link
Contributor

@krombel krombel Apr 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will handle the first event of events and skip the other events of the queue - even if that first one is valid or not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere on my bike ride to/from the pub on Friday night I realised this was exactly what we needed to do, so thanks for actually doing it.

It's somewhat orthogonal, but it would be nice to report metrics on how far behind the loop is, and throw a Measure in somewhere to get metrics on what it's doing.

],
)
except Exception:
logger.exception("Failed to calculate hosts in room")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this happen?

if we're going to do this, surely we should at least log the event id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't happen really, but it empirically seems to have on matrix.org in the past so is probably worth keeping for paranoia's sake.

events_by_room.setdefault(event.room_id, []).append(event)

yield logcontext.make_deferred_yieldable(defer.gatherResults(
[handle_room_events(evs) for evs in events_by_room.itervalues()],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it needs a preserve_fn

@richvdh richvdh assigned erikjohnston and unassigned richvdh Apr 9, 2018
@@ -226,7 +226,10 @@ def handle_room_events(events):
events_by_room.setdefault(event.room_id, []).append(event)

yield logcontext.make_deferred_yieldable(defer.gatherResults(
[handle_room_events(evs) for evs in events_by_room.itervalues()],
[
logcontext.preserve_fn(handle_room_events)(evs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not preserve_fn for every event.. Either preserve_fn once, or use run_in_background (?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do logcontext.run_in_background(handle_room_events(evs))? Isn't that equivalent to preserve_fn?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logcontext.run_in_background(handle_room_events, evs)

And yes it is, except that it doesn't create a new function object on each loop.

@erikjohnston erikjohnston assigned richvdh and unassigned erikjohnston Apr 10, 2018
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@richvdh richvdh assigned erikjohnston and unassigned richvdh Apr 10, 2018
@erikjohnston erikjohnston merged commit 9daf822 into develop Apr 10, 2018
neilisfragile added a commit that referenced this pull request Apr 27, 2018
Changes in synapse v0.28.0-rc1 (2018-04-26)
===========================================

Bug Fixes:

* Fix quarantine media admin API and search reindex (PR #3130)
* Fix media admin APIs (PR #3134)

Changes in synapse v0.28.0-rc1 (2018-04-24)
===========================================

Minor performance improvement to federation sending and bug fixes.

(Note: This release does not include state resolutions discussed in matrix live)

Features:

* Add metrics for event processing lag (PR #3090)
* Add metrics for ResponseCache (PR #3092)

Changes:

* Synapse on PyPy (PR #2760) Thanks to @Valodim!
* move handling of auto_join_rooms to RegisterHandler (PR #2996) Thanks to @krombel!
* Improve handling of SRV records for federation connections (PR #3016) Thanks to @silkeh!
* Document the behaviour of ResponseCache (PR #3059)
* Preparation for py3 (PR #3061, #3073, #3074, #3075, #3103, #3104, #3106, #3107, #3109, #3110) Thanks to @NotAFile!
* update prometheus dashboard to use new metric names (PR #3069) Thanks to @krombel!
* use python3-compatible prints (PR #3074) Thanks to @NotAFile!
* Send federation events concurrently (PR #3078)
* Limit concurrent event sends for a room (PR #3079)
* Improve R30 stat definition (PR #3086)
* Send events to ASes concurrently (PR #3088)
* Refactor ResponseCache usage (PR #3093)
* Clarify that SRV may not point to a CNAME (PR #3100) Thanks to @silkeh!
* Use str(e) instead of e.message (PR #3103) Thanks to @NotAFile!
* Use six.itervalues in some places (PR #3106) Thanks to @NotAFile!
* Refactor store.have_events (PR #3117)

Bug Fixes:

* Return 401 for invalid access_token on logout (PR #2938) Thanks to @dklug!
* Return a 404 rather than a 500 on rejoining empty rooms (PR #3080)
* fix federation_domain_whitelist (PR #3099)
* Avoid creating events with huge numbers of prev_events (PR #3113)
* Reject events which have lots of prev_events (PR #3118)
@erikjohnston erikjohnston deleted the erikj/federation_sender branch September 20, 2018 13:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants