diff options
author | Rory& <root@rory.gay> | 2024-09-02 23:17:46 +0200 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-09-02 23:17:46 +0200 |
commit | 5ce0958bc40144d8622b4be58cf9e84222b08294 (patch) | |
tree | fb37d4793b6e66db43cccd0a3530a8e5c2347cee /host/Rory-nginx | |
parent | Single scrape interval, add synapse label (diff) | |
download | Rory-Open-Architecture-5ce0958bc40144d8622b4be58cf9e84222b08294.tar.xz |
Less synapse workers, add EDU writers
Diffstat (limited to 'host/Rory-nginx')
-rwxr-xr-x | host/Rory-nginx/services/matrix/synapse/synapse-main.nix | 15 | ||||
-rw-r--r-- | host/Rory-nginx/services/matrix/synapse/workers/stream-writers/presence-stream-writer.nix | 123 |
2 files changed, 131 insertions, 7 deletions
diff --git a/host/Rory-nginx/services/matrix/synapse/synapse-main.nix b/host/Rory-nginx/services/matrix/synapse/synapse-main.nix index 68bb866..e8f24d5 100755 --- a/host/Rory-nginx/services/matrix/synapse/synapse-main.nix +++ b/host/Rory-nginx/services/matrix/synapse/synapse-main.nix @@ -12,21 +12,22 @@ nginxVirtualHostName = "matrix.rory.gay"; enableWorkers = true; - federationSenders = 16; + federationSenders = 8; #8 pushers = 1; - mediaRepoWorkers = 4; - clientReaders = 4; - syncWorkers = 4; + mediaRepoWorkers = 2; #4 + clientReaders = 2; #4 + syncWorkers = 2; #4 authWorkers = 1; - federationReaders = 8; - federationInboundWorkers = 8; + federationReaders = 4; #8 + federationInboundWorkers = 4; #8 enableAppserviceWorker = true; enableBackgroundWorker = true; enableUserDirWorker = true; - eventStreamWriters = 8; + eventStreamWriters = 4; #8 + presenceStreamWriters = 2; # https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html settings = { diff --git a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/presence-stream-writer.nix b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/presence-stream-writer.nix new file mode 100644 index 0000000..e906b28 --- /dev/null +++ b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/presence-stream-writer.nix @@ -0,0 +1,123 @@ +{ config, lib, ... }: + +let + cfg = config.services.matrix-synapse; + dbGroup = "medium"; + streamWriterType = "presence"; + workers = lib.range 0 (cfg.presenceStreamWriters - 1); + workerName = "presence_stream_writer"; + workerRoutes = { + client = [ ]; + federation = [ ]; + media = [ ]; + }; +in +let + enabledResources = + lib.optionals (lib.length workerRoutes.client > 0) [ "client" ] + ++ lib.optionals (lib.length workerRoutes.federation > 0) [ "federation" ] + ++ lib.optionals (lib.length workerRoutes.media > 0) [ "media" ]; +in +{ + config = lib.mkIf (cfg.presenceStreamWriters > 0) { + monitoring.synapse.workerNames = lib.map (index: "${workerName}-${toString index}") workers; + services.matrix-synapse = { + settings = { + instance_map = lib.listToAttrs ( + lib.map (index: { + name = "${workerName}-${toString index}"; + value = { + path = "/run/matrix-synapse/${workerName}-${toString index}.sock"; + }; + }) workers + ); + + stream_writers.${streamWriterType} = lib.map (index: "${workerName}-${toString index}") workers; + stream_writers.typing = lib.map (index: "${workerName}-${toString index}") workers; + stream_writers.to_device = lib.map (index: "${workerName}-${toString index}") workers; + stream_writers.account_data = lib.map (index: "${workerName}-${toString index}") workers; + stream_writers.receipts = lib.map (index: "${workerName}-${toString index}") workers; + stream_writers.push_rules = lib.map (index: "${workerName}-${toString index}") workers; + }; + + workers = lib.listToAttrs ( + lib.map (index: { + name = "${workerName}-${toString index}"; + value = { + worker_app = "synapse.app.generic_worker"; + worker_listeners = + [ + { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${toString index}.sock"; + resources = [ + { + names = [ "replication" ]; + compress = false; + } + ]; + } + ] + ++ lib.map (type: { + type = "http"; + path = "/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + mode = "666"; + resources = [ + { + names = [ type ]; + compress = false; + } + ]; + }) enabledResources; + database = ( + import ../../db.nix { + inherit dbGroup; + workerName = "${workerName}-${toString index}"; + } + ); + }; + }) workers + ); + }; + + services.nginx = { + upstreams = lib.listToAttrs ( + lib.map (type: { + name = "${workerName}-${type}"; + value = { + extraConfig = '' + keepalive 32; + least_conn; + ''; + servers = lib.listToAttrs ( + lib.map (index: { + name = "unix:/run/matrix-synapse/${workerName}-${type}-${toString index}.sock"; + value = { + max_fails = 0; + }; + }) workers + ); + }; + }) enabledResources + ); + + virtualHosts."${cfg.nginxVirtualHostName}".locations = lib.listToAttrs ( + lib.flatten ( + lib.forEach enabledResources ( + type: + lib.map (route: { + name = route; + value = { + proxyPass = "http://${workerName}-${type}"; + extraConfig = '' + proxy_http_version 1.1; + proxy_set_header Connection ""; + ''; + }; + }) workerRoutes.${type} + ) + ) + ); + }; + }; +} |