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.
This commit is contained in:
Erik Johnston 2021-06-21 14:38:59 +01:00 committed by GitHub
parent 182147195b
commit a5cd05beee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

1
changelog.d/10221.bugfix Normal file
View File

@ -0,0 +1 @@
Fix performance regression in responding to user key requests over federation. Introduced in v1.34.0rc1.

View File

@ -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: ...

View File

@ -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