summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-06-21 14:38:59 +0100
committerGitHub <noreply@github.com>2021-06-21 14:38:59 +0100
commita5cd05beeeac80df0352bd50c2ad2e017664665c (patch)
tree582741c4805d25a8869d1dbba82f80fe58b7fc14
parentCheck third party rules before persisting knocks over federation (#10212) (diff)
downloadsynapse-a5cd05beeeac80df0352bd50c2ad2e017664665c.tar.xz
Fix performance of responding to user key requests over federation (#10221)
We were repeatedly looking up a config option in a loop (using the
unclassed config style), which is expensive enough that it can cause
large CPU usage.
-rw-r--r--changelog.d/10221.bugfix1
-rw-r--r--synapse/config/_base.pyi2
-rw-r--r--synapse/storage/databases/main/end_to_end_keys.py9
3 files changed, 11 insertions, 1 deletions
diff --git a/changelog.d/10221.bugfix b/changelog.d/10221.bugfix
new file mode 100644
index 0000000000..8853a9bf4e
--- /dev/null
+++ b/changelog.d/10221.bugfix
@@ -0,0 +1 @@
+Fix performance regression in responding to user key requests over federation. Introduced in v1.34.0rc1.
diff --git a/synapse/config/_base.pyi b/synapse/config/_base.pyi
index 844ecd4708..23ca0c83c1 100644
--- a/synapse/config/_base.pyi
+++ b/synapse/config/_base.pyi
@@ -11,6 +11,7 @@ from synapse.config import (
     database,
     emailconfig,
     experimental,
+    federation,
     groups,
     jwt,
     key,
@@ -87,6 +88,7 @@ class RootConfig:
     tracer: tracer.TracerConfig
     redis: redis.RedisConfig
     modules: modules.ModulesConfig
+    federation: federation.FederationConfig
 
     config_classes: List = ...
     def __init__(self) -> None: ...
diff --git a/synapse/storage/databases/main/end_to_end_keys.py b/synapse/storage/databases/main/end_to_end_keys.py
index 9ba5778a88..0e3dd4e9ca 100644
--- a/synapse/storage/databases/main/end_to_end_keys.py
+++ b/synapse/storage/databases/main/end_to_end_keys.py
@@ -62,6 +62,13 @@ class EndToEndKeyBackgroundStore(SQLBaseStore):
 
 
 class EndToEndKeyWorkerStore(EndToEndKeyBackgroundStore):
+    def __init__(self, database: DatabasePool, db_conn: Connection, hs: "HomeServer"):
+        super().__init__(database, db_conn, hs)
+
+        self._allow_device_name_lookup_over_federation = (
+            self.hs.config.federation.allow_device_name_lookup_over_federation
+        )
+
     async def get_e2e_device_keys_for_federation_query(
         self, user_id: str
     ) -> Tuple[int, List[JsonDict]]:
@@ -85,7 +92,7 @@ class EndToEndKeyWorkerStore(EndToEndKeyBackgroundStore):
                     result["keys"] = keys
 
                 device_display_name = None
-                if self.hs.config.allow_device_name_lookup_over_federation:
+                if self._allow_device_name_lookup_over_federation:
                     device_display_name = device.display_name
                 if device_display_name:
                     result["device_display_name"] = device_display_name