From 2bcc81555565059b6a4c6f46291821e2356b2462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Wed, 17 Feb 2021 10:05:26 +0100 Subject: [PATCH] [__matrix_synapse] wire up worker mode --- .../__matrix_synapse/files/homeserver.yaml.sh | 4 +- type/__matrix_synapse/man.rst | 40 ++++++++++++++++++- type/__matrix_synapse/manifest | 16 ++++++-- type/__matrix_synapse/parameter/boolean | 1 + .../parameter/default/background-tasks-worker | 0 .../default/worker-replication-secret | 0 type/__matrix_synapse/parameter/optional | 2 + 7 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 type/__matrix_synapse/parameter/default/background-tasks-worker create mode 100644 type/__matrix_synapse/parameter/default/worker-replication-secret diff --git a/type/__matrix_synapse/files/homeserver.yaml.sh b/type/__matrix_synapse/files/homeserver.yaml.sh index b030fbd..7195dd5 100755 --- a/type/__matrix_synapse/files/homeserver.yaml.sh +++ b/type/__matrix_synapse/files/homeserver.yaml.sh @@ -2825,8 +2825,8 @@ cat << EOF # EOF -if [ -n "$RUN_BACKGROUND_TASKS_ON" ]; then - echo "run_background_tasks_on: ${RUN_BACKGROUND_TASKS_ON:?}" +if [ -n "$BACKGROUND_TASKS_WORKER" ]; then + echo "run_background_tasks_on: ${BACKGROUND_TASKS_WORKER:?}" fi cat << EOF diff --git a/type/__matrix_synapse/man.rst b/type/__matrix_synapse/man.rst index db67b59..ead1649 100644 --- a/type/__matrix_synapse/man.rst +++ b/type/__matrix_synapse/man.rst @@ -146,6 +146,15 @@ auto-join-room app-service-config-file Path (on remote) of an application service configuration file to load. Can be specified multiple times. +worker-replication-secret + A shared secret used by the replication APIs to authenticate HTTP requests + from workers. Ignored if worker-mode is not set. By default this is unused and + traffic is not authenticated. + +background-task-worker + The worker that is used to run background tasks (e.g. cleaning up expired + data). If not provided this defaults to the main process. + extra-setting Arbitrary string to be added to the configuration file. Can be specified multiple times. @@ -214,6 +223,13 @@ enable-message-retention-policy filter events received over federation so that events that should have been purged are ignored and not stored again. See message-max-lifetime flag. +worker-mode + For small instances it recommended to run Synapse in the default monolith + mode. For larger instances where performance is a concern it can be helpful + to split out functionality into multiple separate python processes. These + processes are called 'workers'. Please read the WORKER MODE section of this + manpage before enabling, as extra work and considerations are required. + PERFORMANCE ----------- @@ -230,7 +246,29 @@ tuning: WORKER MODE ----------- -Not implemented yet. +Worker mode allows to move some processing out of the main synapse process for +horizontal scaling. You are expected to use the +`cdist-type__matrix_synapse_worker(7) +`_ type to set up workers when the +worker-mode flag is set. + +Worker mode depend on the following components: + + * A working `redis `_ server + * The hiredis python package (`python3-hiredis + `_ on debian, not + packaged in alpine as of 2021-02-17). + * The txredisapi python package, which is not packaged on debian nor alpine + as of 2021-02-17. + +The current way to install the above two python packages (if not packaged in +your distribution) is sadly to use pip (see `cdist-type__python_pip(7) +`_ core cdist type). + +It is also recommended to first take a look at: + + - `upstream's high-level overview on workers (matrix.org blog post) `_ + - `upstream's documentation on workers `_ EXAMPLES -------- diff --git a/type/__matrix_synapse/manifest b/type/__matrix_synapse/manifest index 1f01ca9..6341461 100755 --- a/type/__matrix_synapse/manifest +++ b/type/__matrix_synapse/manifest @@ -167,7 +167,7 @@ if [ -f "$__object/parameter/notification-from" ]; then NOTIFICATION_FROM=$(cat "$__object/parameter/notification-from") export NOTIFICATION_FROM else - export NOTIFICATION_FROM="Matrix " + export NOTIFICATION_FROM="%(app)s " fi # Registrations and users. @@ -243,15 +243,23 @@ fi export MAIN_LISTENER_PORT=8008 export ENABLE_MEDIA_REPO='true' export SEND_FEDERATION_FROM_MAIN_PROCESS='true' -export RUN_BACKGROUND_TASKS_ON= -export ENABLE_REPLICATION= -export ENABLE_REDIS_SUPPORT='false' MAIN_LISTENER_RESOURCES="[federation,client]" if [ "$EXPOSE_METRICS" = "true" ]; then MAIN_LISTENER_RESOURCES="$(echo "$MAIN_LISTENER_RESOURCES" | tr -d ']'),metrics]" fi export MAIN_LISTENER_RESOURCES +ENABLE_REPLICATION= +ENABLE_REDIS_SUPPORT='false' +WORKER_REPLICATION_SECRET=$(cat "$__object/parameter/worker-replication-secret") +BACKGROUND_TASKS_WORKER=$(cat "$__object/parameter/background-tasks-worker") +if [ -f "$__object/parameter/worker-mode" ]; then + ENABLE_REPLICATION=1 + ENABLE_REDIS_SUPPORT='true' +fi +export ENABLE_REPLICATION ENABLE_REDIS_SUPPORT WORKER_REPLICATION_SECRET \ + BACKGROUND_TASKS_WORKER + # Error out on invalid parameter combination. case "$DATABASE_ENGINE" in sqlite3) diff --git a/type/__matrix_synapse/parameter/boolean b/type/__matrix_synapse/parameter/boolean index ed738fe..481fb9d 100644 --- a/type/__matrix_synapse/parameter/boolean +++ b/type/__matrix_synapse/parameter/boolean @@ -15,3 +15,4 @@ disable-presence ldap-use-starttls user-directory-search-all-users enable-message-retention-policy +worker-mode diff --git a/type/__matrix_synapse/parameter/default/background-tasks-worker b/type/__matrix_synapse/parameter/default/background-tasks-worker new file mode 100644 index 0000000..e69de29 diff --git a/type/__matrix_synapse/parameter/default/worker-replication-secret b/type/__matrix_synapse/parameter/default/worker-replication-secret new file mode 100644 index 0000000..e69de29 diff --git a/type/__matrix_synapse/parameter/optional b/type/__matrix_synapse/parameter/optional index 73a7dfa..16d1dd4 100644 --- a/type/__matrix_synapse/parameter/optional +++ b/type/__matrix_synapse/parameter/optional @@ -27,3 +27,5 @@ remote-room-complexity-treshold room-encryption-policy notification-from message-max-lifetime +worker-replication-secret +background-tasks-worker