From f2f3d2eba3e4cc93c0c7a22a85c4402b64678b2b Mon Sep 17 00:00:00 2001 From: Catalan Lover Date: Sat, 3 Feb 2024 00:54:00 +0100 Subject: [PATCH] Upgrade Synapse Cache Autotune to auto configure memory use --- roles/custom/matrix-synapse/defaults/main.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index 2387d11bd..0f7a3c7dc 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -544,18 +544,29 @@ matrix_synapse_password_config_localdb_enabled: true # Controls the number of events that Synapse caches in memory. matrix_synapse_event_cache_size: "100K" + + + # Controls cache sizes for Synapse. # Raise this to increase cache sizes or lower it to potentially lower memory use. # To learn more, see: # - https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#caching # - https://github.com/matrix-org/synapse/issues/3939 +# Defaults for timings of caches is from https://tcpipuk.github.io/synapse/deployment/synapse.html +# The idea with the timings used is that you get to evict soon but also you keep stuff around for a long time when its not forced out. +# Long cache lifetimes together with the low minimum TTL allows autotune to be the primary eviction method assuming size of cache is hit before we hit other caps. matrix_synapse_caches_global_factor: 10 matrix_synapse_caches_expire_caches: true -matrix_synapse_caches_cache_entry_ttl: "30m" +matrix_synapse_caches_cache_entry_ttl: "1080m" matrix_synapse_caches_sync_response_cache_duration: "2m" -matrix_synapse_caches_autotuning_max_cache_memory_usage: "2048M" -matrix_synapse_caches_autotuning_target_cache_memory_usage: "1024M" -matrix_synapse_caches_autotuning_min_cache_ttl: "5m" +matrix_synapse_caches_autotuning_min_cache_ttl: "30s" +# The Cache tune math used here is a derivative of the same math used to autotune sizes for postgres. +# The memtotal variable can in theory be overiden to make Synapse think it has less ram to work with. +# But if your at the point of considering that just override the math or put static values in. +matrix_synapse_memtotal_kb: "{{ ansible_memtotal_mb*1024|int }}" +matrix_synapse_caches_autotuning_max_cache_memory_usage: "{{ 2097152 if (matrix_synapse_memtotal_kb|int/8)/1024 >= 2048 else matrix_synapse_memtotal_kb|int/8 }}" +matrix_synapse_caches_autotuning_target_cache_memory_usage: "{{ 1048576 if (matrix_synapse_memtotal_kb|int/16)/1024 >= 1024 else matrix_synapse_memtotal_kb|int/16 }}" + # Controls whether Synapse will federate at all. # Disable this to completely isolate your server from the rest of the Matrix network.