element-hq / element-hq/synapse
High CPU and memory usage
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
Sorry to ask this question here, but I can't even connect (or can, but it's slow) to my remote server over SSH because of this issue.
I'm new to matrix and especially synapse, and here's my problem:
When synapse is running, it uses about 100% of the CPU and >80% of the RAM (1.6GB).
Also, my nginx logs indicate that it receives `PUT /_matrix/federation/v1/send/` ~30-50 times per minute, but I do not know if this could be related.
Few examples:
```
- - [12/Oct/2025:09:03:22 +0000] "PUT /_matrix/federation/v1/send/ HTTP/1.1" 502 157 "-" "Synapse/1.134.0"
- - [12/Oct/2025:09:03:39 +0000] "PUT /_matrix/federation/v1/send/ HTTP/1.1" 200 21 "-" "Synapse/1.117.0"
- - [12/Oct/2025:09:04:47 +0000] "PUT /_matrix/federation/v1/send/ HTTP/1.1" 401 197 "-" "Synapse/1.136.0"
```
I have a pretty weak VPS with 1 core and 2 GB of RAM but I hope it's enough to run matrix node. How can I understand why synapse consumes so much memory and can I reduce it?
Homeserver settings:
```yaml
pid_file: "/var/run/matrix-synapse.pid"
listeners:
- port: 8008
tls: false
type: http
x_forwarded: true
bind_addresses: ['127.0.0.1']
resources:
- names: [client, federation]
compress: false
database:
name: psycopg2
txn_limit: 10000
args:
user: synapse_user
password: SECRET
database: synapse
host: localhost
port: 5432
cp_min: 5
cp_max: 10
log_config: "/etc/matrix-synapse/log.yaml"
media_store_path: /var/lib/matrix-synapse/media
signing_key_path: "/etc/matrix-synapse/homeserver.signing.key"
trusted_key_servers:
- server_name: MYDOMAIN
suppress_key_server_warning: true
max_upload_size: 10M
enable_registration: false
turn_uris: ["turn:matrix.MYDOMAIN?transport=udp","turn:matrix.MYDOMAIN?transport=tcp"]
turn_shared_secret: SECRET
turn_user_lifetime: 86400000
registration_shared_secret: SECRET
macaroon_secret_key: SECRET
allow_public_rooms_over_federation: true
allow_public_rooms_without_auth: true
```
Nginx:
```nginx
# matrix server
server {
listen 443 ssl;
listen [::]:443 ssl;
listen 8448 ssl default_server;
listen [::]:8448 ssl default_server;
server_name matrix.MYDOMAIN;
# ssl settings omitted
location / {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
}
location ~ ^(/_matrix|/_synapse/client) {
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host:$server_port;
client_max_body_size 11M;
proxy_http_version 1.1;
}
}
# delegation
server {
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
server_name MYDOMAIN;
# ssl settings omitted
location /.well-known/matrix/client {
return 200 '{"m.homeserver": {"base_url": "https://matrix.MYDOMAIN"}}';
default_type application/json;
add_header Access-Control-Allow-Origin *;
}
location /.well-known/matrix/server {
return 200 '{"m.server": "matrix.MYDOMAIN:443"}';
default_type application/json;
add_header Access-Control-Allow-Origin *;
}
}
```
EDIT
There are suspiciously many reqords in my synapse logs, and they are growing rapidly. Within one second, 1,700 records were made, and this happens constantly while synapse is running. I'm not sure can I share my logs but it have `INFO` level and here is some records:
```
2025-10-12 09:23:57,584 - synapse.http.matrixfederationclient - 369 - INFO - sync_partial_state_room-0-$YmV3eJuqhITkAkQCMcvkvNyUERkkFyOIbQczHMGF-$mxvTsNoMRXfQNtOUCU1nYZiXFsmw7B3CQ-h2XnJi - {POST-O-6360} [beta2.matrix.org] Completed request: 200 OK in 19.61 secs, got 24 bytes - POST matrix-federation://beta2.matrix.org/_matrix/policy/unstable/org.matrix.msc4284/event/$LyvSnufVzWjM3ClafRPctwIXxfv4ZeS7uOXjGG5fTWE/check
Thousands of that in a few seconds, tens of thousands across all log...
```
```
2025-10-12 09:40:58,524 - synapse.federation.federation_client - 834 - WARNING - sync_partial_state_room-0-$YmV3eJuqhITkAkQCMcvkvNyUERkkFyOIbQczHMGF-$mxvTsNoMRXfQNtOUCU1nYZiXFsmw7B3CQ-h2XnJi - Signature on retrieved event $m_01OyOe0-BV3OSTHlZG6YC4bIFOrqhJ8KdCjAt was invalid (unable to verify signature for sender domain erb.pw: 401: Failed to find any key to satisfy: _FetchKeyRequest(server_name='erb.pw', minimum_valid_until_ts=1698939776467, key_ids=['ed25519:a_WpbR'])). Checking local store/origin server
This kind of record happens very frequently as well
```
Contributor guide
Assessment
This issue has not been assessed yet.