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

Commit

Permalink
Fix performance of responding to user key requests over federation (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
erikjohnston authored Jun 21, 2021
1 parent 1821471 commit a5cd05b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10221.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix performance regression in responding to user key requests over federation. Introduced in v1.34.0rc1.
2 changes: 2 additions & 0 deletions synapse/config/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from synapse.config import (
database,
emailconfig,
experimental,
federation,
groups,
jwt,
key,
Expand Down Expand Up @@ -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: ...
Expand Down
9 changes: 8 additions & 1 deletion synapse/storage/databases/main/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def __init__(self, database: DatabasePool, db_conn: Connection, hs: "HomeServer"


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]]:
Expand All @@ -85,7 +92,7 @@ async def get_e2e_device_keys_for_federation_query(
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
Expand Down

0 comments on commit a5cd05b

Please sign in to comment.