summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-05-04 17:59:35 +0100
committerErik Johnston <erik@matrix.org>2021-05-04 17:59:35 +0100
commit04db7b9581e101364599e40e67364a8f801694c8 (patch)
tree0f51d224c53dc9884a9dafded64f7fe14d8307de
parentMerge branch 'erikj/efficient_presence_join' into erikj/test_send (diff)
parentDocument default. Add type annotations. Correctly convert to seconds (diff)
downloadsynapse-04db7b9581e101364599e40e67364a8f801694c8.tar.xz
Merge branch 'erikj/limit_how_often_gc' into erikj/test_send
-rw-r--r--docs/sample_config.yaml6
-rw-r--r--synapse/config/server.py28
-rw-r--r--synapse/metrics/__init__.py8
3 files changed, 32 insertions, 10 deletions
diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml
index 9e22696170..f469d6e54f 100644
--- a/docs/sample_config.yaml
+++ b/docs/sample_config.yaml
@@ -155,10 +155,12 @@ presence:
 # The minimum time in seconds between each GC for a generation, regardless of
 # the GC thresholds. This ensures that we don't do GC too frequently.
 #
-# A value of `[1, 10, 30]` indicates that a second must pass between consecutive
+# A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
 # generation 0 GCs, etc.
 #
-# gc_min_seconds_between: [1, 10, 30]
+# Defaults to `[1s, 10s, 30s]`.
+#
+#gc_min_interval: [0.5s, 30s, 1m]
 
 # Set the limit on the returned events in the timeline in the get
 # and sync operations. The default value is 100. -1 means no upper limit.
diff --git a/synapse/config/server.py b/synapse/config/server.py
index ca1c9711f8..c290a35a92 100644
--- a/synapse/config/server.py
+++ b/synapse/config/server.py
@@ -19,7 +19,7 @@ import logging
 import os.path
 import re
 from textwrap import indent
-from typing import Any, Dict, Iterable, List, Optional, Set
+from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
 
 import attr
 import yaml
@@ -572,7 +572,7 @@ class ServerConfig(Config):
             _warn_if_webclient_configured(self.listeners)
 
         self.gc_thresholds = read_gc_thresholds(config.get("gc_thresholds", None))
-        self.gc_seconds = read_gc_thresholds(config.get("gc_min_seconds_between", None))
+        self.gc_seconds = self.read_gc_intervals(config.get("gc_min_interval", None))
 
         @attr.s
         class LimitRemoteRoomsConfig:
@@ -921,10 +921,12 @@ class ServerConfig(Config):
         # The minimum time in seconds between each GC for a generation, regardless of
         # the GC thresholds. This ensures that we don't do GC too frequently.
         #
-        # A value of `[1, 10, 30]` indicates that a second must pass between consecutive
+        # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
         # generation 0 GCs, etc.
         #
-        # gc_min_seconds_between: [1, 10, 30]
+        # Defaults to `[1s, 10s, 30s]`.
+        #
+        #gc_min_interval: [0.5s, 30s, 1m]
 
         # Set the limit on the returned events in the timeline in the get
         # and sync operations. The default value is 100. -1 means no upper limit.
@@ -1314,6 +1316,24 @@ class ServerConfig(Config):
             help="Turn on the twisted telnet manhole service on the given port.",
         )
 
+    def read_gc_intervals(self, durations) -> Optional[Tuple[float, float, float]]:
+        """Reads the three durations for the GC min interval option, returning seconds."""
+        if durations is None:
+            return None
+
+        try:
+            if len(durations) != 3:
+                raise ValueError()
+            return (
+                self.parse_duration(durations[0]) / 1000,
+                self.parse_duration(durations[1]) / 1000,
+                self.parse_duration(durations[2]) / 1000,
+            )
+        except Exception:
+            raise ConfigError(
+                "Value of `gc_min_interval` must be a list of three durations if set"
+            )
+
 
 def is_threepid_reserved(reserved_threepids, threepid):
     """Check the threepid against the reserved threepid config
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py
index c841363b1e..d58071c81d 100644
--- a/synapse/metrics/__init__.py
+++ b/synapse/metrics/__init__.py
@@ -540,10 +540,10 @@ REGISTRY.register(ReactorLastSeenMetric())
 
 # The minimum time in seconds between GCs for each generation, regardless of the current GC
 # thresholds and counts.
-MIN_TIME_BETWEEN_GCS = [1, 10, 30]
+MIN_TIME_BETWEEN_GCS = (1.0, 10.0, 30.0)
 
-# The time in seconds of the last time we did a GC for each generation.
-_last_gc = [0, 0, 0]
+# The time (in seconds since the epoch) of the last time we did a GC for each generation.
+_last_gc = [0.0, 0.0, 0.0]
 
 
 def runUntilCurrentTimer(reactor, func):
@@ -604,7 +604,7 @@ def runUntilCurrentTimer(reactor, func):
                 unreachable = gc.collect(i)
                 end = time.time()
 
-                _last_gc[i] = int(end)
+                _last_gc[i] = end
 
                 gc_time.labels(i).observe(end - start)
                 gc_unreachable.labels(i).set(unreachable)