element-hq / element-hq/synapse

[Presence] Huge spike in CPU usage/Federation traffic approximately every 25 minutes

Open
#15,878 1 comment 0 reactions 0 assignees View on GitHub
A-Presence O-Occasional S-Minor T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#15878](https://github.com/matrix-org/synapse/issues/15878).

---

There is a `FEDERATION_PING_INTERVAL` for when to send a ping over federation every 25 minutes that keeps a user from being marked 'offline' before the 30 minute `FEDERATION_TIMEOUT` hits.

https://github.com/element-hq/synapse/blob/4d8905a15a417ed0054ec2533d243932d890bbbd/synapse/handlers/presence.py#L194-L198

![Federation spike 1](https://github.com/matrix-org/synapse/assets/1582365/2a05bc9d-6510-4df9-af54-b1d96244f028)

This appears to be the replication notifier system ramping up and queueing a bunch of federation sending requests over approximately 1 minute worth of time(give or take a few seconds)
Images

![Federation spike 2](https://github.com/matrix-org/synapse/assets/1582365/6042747f-3a96-439c-9123-36ad500b1006)

![Federation spike 3](https://github.com/matrix-org/synapse/assets/1582365/260d263f-0bd0-419a-88dc-ea6ae52fa1df)

![Federation spike 4](https://github.com/matrix-org/synapse/assets/1582365/7ece6833-c9d3-4f26-90b9-78a08b483d3a)

There is a database hit during this to `get_current_hosts_in_room()`, I'm not personally convinced it's contributing to the seriousness of this situation(but included here for completeness).
Images:

![Federation spike 5](https://github.com/matrix-org/synapse/assets/1582365/2cdee10a-590b-49a9-a7a8-bab73a48f439)

UPDATE: Additional information from the other side of the slash in the title

The large spike in traffic caused by queueing and then sending all those requests looks like this:
![Federation spike 7](https://github.com/matrix-org/synapse/assets/1582365/32f61ab9-9f4d-47d5-812c-6723d39ba992)

Contributor guide

Open the contributing guide

Research direction

Start in synapse/handlers/presence.py around FEDERATION_PING_INTERVAL and FEDERATION_TIMEOUT, then trace how the replication notifier queues federation sending requests. Check the get_current_hosts_in_room() database activity during the spike. Done means identifying the cause of the periodic CPU and federation-traffic surge and defining a verified mitigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, distributed-systems, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.