Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 20e7c4d

Browse files
committed
Add an improved "forward extremities" metric
Hopefully, N(extremities) * N(state_events) is a more realistic approximation to "how big a problem is this room?".
1 parent 6d2d42f commit 20e7c4d

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

synapse/storage/databases/main/metrics.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
buckets=[1, 2, 3, 5, 7, 10, 15, 20, 50, 100, 200, 500],
3030
)
3131

32+
# we also expose metrics on the "number of excess extremity events", which is
33+
# (E-1)*N, where E is the number of extremities and N is the number of state
34+
# events in the room. This is an approximation to the number of state events
35+
# we could remove from state resolution by reducing the graph to a single
36+
# forward extremity.
37+
_excess_state_events_collecter = GaugeBucketCollector(
38+
"synapse_excess_extremity_events",
39+
"Number of rooms on the server with the given number of excess extremity "
40+
"events, or fewer",
41+
buckets=[0] + [1 << n for n in range(12)],
42+
)
43+
3244

3345
class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
3446
"""Functions to pull various metrics from the DB, for e.g. phone home
@@ -52,15 +64,26 @@ async def _read_forward_extremities(self):
5264
def fetch(txn):
5365
txn.execute(
5466
"""
55-
select count(*) c from event_forward_extremities
56-
group by room_id
67+
SELECT t1.c, t2.c
68+
FROM (
69+
SELECT room_id, COUNT(*) c FROM event_forward_extremities
70+
GROUP BY room_id
71+
) t1 LEFT JOIN (
72+
SELECT room_id, COUNT(*) c FROM current_state_events
73+
GROUP BY room_id
74+
) t2 ON t1.room_id = t2.room_id
5775
"""
5876
)
5977
return txn.fetchall()
6078

6179
res = await self.db_pool.runInteraction("read_forward_extremities", fetch)
80+
6281
_extremities_collecter.update_data(x[0] for x in res)
6382

83+
_excess_state_events_collecter.update_data(
84+
(x[0] - 1) * x[1] for x in res if x[1]
85+
)
86+
6487
async def count_daily_messages(self):
6588
"""
6689
Returns an estimate of the number of messages sent in the last day.

0 commit comments

Comments
 (0)