This commit is contained in:
deathrow 2022-11-04 16:28:02 -04:00
parent fec2f932c4
commit 4e6be6304d
No known key found for this signature in database
GPG key ID: FF39D67A22069F73
11 changed files with 424 additions and 38 deletions

View file

@ -0,0 +1,30 @@
# Choose sync worker based on the existence of "since" query parameter
map $arg_since $sync {
default sync_worker;
'' sync_init;
}
# Sync initial/normal
location ~ ^/_matrix/client/(r0|v3)/sync$ {
include snippets/matrix-proxy-headers.conf;
proxy_pass http://$sync;
proxy_read_timeout 1h;
}
# Normal sync
location ~ ^/_matrix/client/(api/v1|r0|v3)/events$ {
include snippets/matrix-proxy-headers.conf;
proxy_pass http://sync_worker;
}
# Initial_sync
location ~ ^/_matrix/client/(api/v1|r0|v3)/initialSync$ {
include snippets/matrix-proxy-headers.conf;
proxy_pass http://sync_init;
proxy_read_timeout 1h;
}
location ~ ^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$ {
include snippets/matrix-proxy-headers.conf;
proxy_pass http://sync_init;
proxy_read_timeout 1h;
}

View file

@ -2,23 +2,43 @@ upstream generic_worker_ih {
ip_hash;
server synapse-generic-worker-1:8080;
server synapse-generic-worker-2:8081;
server sync1:8090;
server sync2:8091;
server sync3:8092;
server synapse-generic-worker-3:8082;
server synapse-generic-worker-4:8083;
}
upstream generic_worker_lc {
least_conn;
server synapse-generic-worker-1:8080;
server synapse-generic-worker-2:8081;
server synapse-generic-worker-3:8082;
server synapse-generic-worker-4:8083;
}
# extract username from token get parameter
map $arg_access_token $token_from_arg {
default $arg_access_token;
"~syt_(?<username>.*?)_.*" $username;
}
# extract username part from bearer token, fallback to access_token
map $http_authorization $proxy_username_label {
default $http_authorization;
"~Bearer syt_(?<username>.*?)_.*" $username;
"" $token_from_arg;
}
upstream sync_worker {
# pin with username extracted from bearer token or access_token
hash $proxy_username_label consistent;
server sync1:8090;
server sync2:8091;
server sync3:8092;
}
upstream sync_worker {
ip_hash;
server sync1:8090;
server sync2:8091;
server sync3:8092;
upstream sync_init {
# Use the username mapper result for hash key
hash $mxid_localpart consistent;
server sync4:8093;
server sync5:8094;
}