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

Commit

Permalink
Add an improved "forward extremities" metric
Browse files Browse the repository at this point in the history
Hopefully, N(extremities) * N(state_events) is a more realistic approximation
to "how big a problem is this room?".
  • Loading branch information
richvdh committed Sep 30, 2020
1 parent 6d2d42f commit 20e7c4d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions synapse/storage/databases/main/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
buckets=[1, 2, 3, 5, 7, 10, 15, 20, 50, 100, 200, 500],
)

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


class ServerMetricsStore(EventPushActionsWorkerStore, SQLBaseStore):
"""Functions to pull various metrics from the DB, for e.g. phone home
Expand All @@ -52,15 +64,26 @@ async def _read_forward_extremities(self):
def fetch(txn):
txn.execute(
"""
select count(*) c from event_forward_extremities
group by room_id
SELECT t1.c, t2.c
FROM (
SELECT room_id, COUNT(*) c FROM event_forward_extremities
GROUP BY room_id
) t1 LEFT JOIN (
SELECT room_id, COUNT(*) c FROM current_state_events
GROUP BY room_id
) t2 ON t1.room_id = t2.room_id
"""
)
return txn.fetchall()

res = await self.db_pool.runInteraction("read_forward_extremities", fetch)

_extremities_collecter.update_data(x[0] for x in res)

_excess_state_events_collecter.update_data(
(x[0] - 1) * x[1] for x in res if x[1]
)

async def count_daily_messages(self):
"""
Returns an estimate of the number of messages sent in the last day.
Expand Down

0 comments on commit 20e7c4d

Please sign in to comment.