synapse icon indicating copy to clipboard operation
synapse copied to clipboard

Check appservice user interest against the local users instead of all users (`get_users_in_room` mis-use)

Open MadLittleMods opened this issue 3 years ago • 1 comments

Check appservice user interest against the local users instead of all users (get_users_in_room mis-use).

get_local_users_in_room is way more performant since it looks at a single table (local_current_membership) and is looking through way less data since it only worries about the local users in the room instead of everyone in the room across the federation.

Fix https://github.com/matrix-org/synapse/issues/13942 (probably fixes, we don't know for sure but it's our hunch atm)

Related to https://github.com/matrix-org/matrix-spec/issues/1272

Related to the following PRs where we also cleaned up some get_users_in_room mis-uses:

  • https://github.com/matrix-org/synapse/pull/13605
  • https://github.com/matrix-org/synapse/pull/13608
  • https://github.com/matrix-org/synapse/pull/13606
  • https://github.com/matrix-org/synapse/pull/13960

See https://github.com/matrix-org/synapse/pull/13575#discussion_r953023755 for the original exploration around finding get_users_in_room mis-uses.

Problem

https://github.com/matrix-org/synapse/pull/13575 made the get_users_in_room SQL query a little more complicated by adding an extra join statement to the query which means it takes more time.

This extra database time can show up as a hot-spot for homeservers that make heavy use of application services and bridged users (like Element One), see https://github.com/matrix-org/synapse/issues/13942

Pull Request Checklist

  • [x] Pull request is based on the develop branch
  • [x] Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • [ ] ~~Pull request includes a sign off~~
  • [x] Code style is correct (run the linters)

MadLittleMods avatar Sep 29 '22 22:09 MadLittleMods

Thanks for the review @squahtx, @clokep, and @anoadragon453 🐎

MadLittleMods avatar Sep 30 '22 19:09 MadLittleMods

Thanks for the review @squahtx, @clokep, @anoadragon453, and @turt2live 🦨

MadLittleMods avatar Oct 27 '22 18:10 MadLittleMods