diff options
-rw-r--r-- | docs/sample_config.yaml | 19 | ||||
-rw-r--r-- | synapse/app/_base.py | 19 | ||||
-rw-r--r-- | synapse/config/_base.pyi | 2 | ||||
-rw-r--r-- | synapse/config/homeserver.py | 2 | ||||
-rw-r--r-- | synapse/config/state_compressor.py | 50 |
5 files changed, 87 insertions, 5 deletions
diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index 95cca16552..1ca4557b0f 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -2644,3 +2644,22 @@ redis: # Optional password if configured on the Redis instance # #password: <secret_password> + + +# The state compressor is an experimental tool which attempts to +# reduce the number of rows in the state_groups_state table +# of postgres databases. +# +# For more information please see +# https://matrix-org.github.io/synapse/latest/state_compressor.html +# +state_compressor: +# enabled: true +# # The (rough) number of state groups to load at one time +# chunk_size: 500 +# # The number of rooms to compress on each run +# number_of_rooms: 5 +# # The default level sizes for the compressor to use +# default_levels: 100,50,25 +# # How frequently to run the state compressor +# time_between_runs: 1d diff --git a/synapse/app/_base.py b/synapse/app/_base.py index a206c0015c..cc2ddfe0c1 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py @@ -426,10 +426,17 @@ async def start(hs: "HomeServer"): def setup_state_compressor(hs): """Schedules the state compressor to run regularly""" - db_config = hs.config.get_single_database().config + compressor_config = hs.config.statecompressor + # Check that compressor is enabled + if not compressor_config.enabled: + return + + # Check that the database being used is postgres + db_config = hs.config.database.get_single_database().config if db_config["name"] != "psycopg2": return + # construct the database URL from the database config db_args = db_config["args"] db_url = "postgresql://{username}:{password}@{host}:{port}/{database}".format( username=db_args["user"], @@ -439,6 +446,7 @@ def setup_state_compressor(hs): database=db_args["database"], ) + # The method to be called periodically def run_state_compressor(): run_as_background_process( desc="State Compressor", @@ -446,15 +454,16 @@ def setup_state_compressor(hs): reactor=hs.get_reactor(), f=auto_compressor.compress_largest_rooms, db_url=db_url, - chunk_size=10, - default_levels="100,50,25", - number_of_rooms=10, + chunk_size=compressor_config.chunk_size, + default_levels=compressor_config.default_levels, + number_of_rooms=compressor_config.number_of_rooms, ) + # Call the compressor every `time_between_runs` milliseconds clock = hs.get_clock() clock.looping_call( run_state_compressor, - 1 * 60 * 1000, + compressor_config.time_between_runs, ) diff --git a/synapse/config/_base.pyi b/synapse/config/_base.pyi index 06fbd1166b..b925f692b0 100644 --- a/synapse/config/_base.pyi +++ b/synapse/config/_base.pyi @@ -32,6 +32,7 @@ from synapse.config import ( server_notices, spam_checker, sso, + state_compressor, stats, third_party_event_rules, tls, @@ -91,6 +92,7 @@ class RootConfig: modules: modules.ModulesConfig caches: cache.CacheConfig federation: federation.FederationConfig + statecompressor: state_compressor.StateCompressorConfig config_classes: List = ... def __init__(self) -> None: ... diff --git a/synapse/config/homeserver.py b/synapse/config/homeserver.py index 442f1b9ac0..003cffdab9 100644 --- a/synapse/config/homeserver.py +++ b/synapse/config/homeserver.py @@ -45,6 +45,7 @@ from .server import ServerConfig from .server_notices import ServerNoticesConfig from .spam_checker import SpamCheckerConfig from .sso import SSOConfig +from .state_compressor import StateCompressorConfig from .stats import StatsConfig from .third_party_event_rules import ThirdPartyRulesConfig from .tls import TlsConfig @@ -97,4 +98,5 @@ class HomeServerConfig(RootConfig): WorkerConfig, RedisConfig, ExperimentalConfig, + StateCompressorConfig, ] diff --git a/synapse/config/state_compressor.py b/synapse/config/state_compressor.py new file mode 100644 index 0000000000..0ab65f608d --- /dev/null +++ b/synapse/config/state_compressor.py @@ -0,0 +1,50 @@ +# Copyright 2021 The Matrix.org Foundation C.I.C. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from synapse.config._base import Config + + +class StateCompressorConfig(Config): + section = "statecompressor" + + def read_config(self, config, **kwargs): + compressor_config = config.get("state_compressor", {}) + self.enabled = compressor_config.get("enabled", False) + self.chunk_size = compressor_config.get("chunk_size", 500) + self.number_of_rooms = compressor_config.get("number_of_rooms", 5) + self.default_levels = compressor_config.get("default_levels", "100,50,25") + self.time_between_runs = self.parse_duration( + compressor_config.get("time_between_runs", "1d") + ) + + def generate_config_section(self, **kwargs): + return """\ + # The state compressor is an experimental tool which attempts to + # reduce the number of rows in the state_groups_state table + # of postgres databases. + # + # For more information please see + # https://matrix-org.github.io/synapse/latest/state_compressor.html + # + state_compressor: + # enabled: true + # # The (rough) number of state groups to load at one time + # chunk_size: 500 + # # The number of rooms to compress on each run + # number_of_rooms: 5 + # # The default level sizes for the compressor to use + # default_levels: 100,50,25 + # # How frequently to run the state compressor + # time_between_runs: 1d + """ |