From 36383d48f3efa01039898dac294ecce0aa2d172e Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 4 Apr 2022 19:07:49 +0100 Subject: [PATCH 1/3] Prefill the device_list_stream_cache --- synapse/replication/slave/storage/devices.py | 12 +++++++++++- synapse/storage/databases/main/__init__.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/synapse/replication/slave/storage/devices.py b/synapse/replication/slave/storage/devices.py index 0ffd34f1dad0..a0dd9d2b893c 100644 --- a/synapse/replication/slave/storage/devices.py +++ b/synapse/replication/slave/storage/devices.py @@ -47,8 +47,18 @@ def __init__( ], ) device_list_max = self._device_list_id_gen.get_current_token() + device_list_prefill, min_device_list_id = self.db_pool.get_cache_dict( + db_conn, + "device_lists_stream", + entity_column="user_id", + stream_column="stream_id", + max_value=device_list_max, + limit=1000, + ) self._device_list_stream_cache = StreamChangeCache( - "DeviceListStreamChangeCache", device_list_max + "DeviceListStreamChangeCache", + min_device_list_id, + prefilled_cache=device_list_prefill, ) self._user_signature_stream_cache = StreamChangeCache( "UserSignatureStreamChangeCache", device_list_max diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py index f024761ba7b8..68abf6783fea 100644 --- a/synapse/storage/databases/main/__init__.py +++ b/synapse/storage/databases/main/__init__.py @@ -183,8 +183,18 @@ def __init__( super().__init__(database, db_conn, hs) device_list_max = self._device_list_id_gen.get_current_token() + device_list_prefill, min_device_list_id = self.db_pool.get_cache_dict( + db_conn, + "device_lists_stream", + entity_column="user_id", + stream_column="stream_id", + max_value=device_list_max, + limit=1000, + ) self._device_list_stream_cache = StreamChangeCache( - "DeviceListStreamChangeCache", device_list_max + "DeviceListStreamChangeCache", + min_device_list_id, + prefilled_cache=device_list_prefill, ) self._user_signature_stream_cache = StreamChangeCache( "UserSignatureStreamChangeCache", device_list_max From f986db2adb6f1e97a51299fb5af6abfa49e24f19 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 4 Apr 2022 19:08:42 +0100 Subject: [PATCH 2/3] Newsfile --- changelog.d/12367.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12367.feature diff --git a/changelog.d/12367.feature b/changelog.d/12367.feature new file mode 100644 index 000000000000..89403ceeef32 --- /dev/null +++ b/changelog.d/12367.feature @@ -0,0 +1 @@ +Reduce overhead of restarting synchrotrons From ea2d01366ce2a68c11b0ed8f21d90a6596463215 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 4 Apr 2022 19:13:58 +0100 Subject: [PATCH 3/3] Newsfile --- changelog.d/12367.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/12367.feature b/changelog.d/12367.feature index 89403ceeef32..34bb60e96601 100644 --- a/changelog.d/12367.feature +++ b/changelog.d/12367.feature @@ -1 +1 @@ -Reduce overhead of restarting synchrotrons +Reduce overhead of restarting synchrotrons.