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

Commit

Permalink
Track a histogram of state res durations (#13036)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson authored Jun 15, 2022
1 parent 0dbdc39 commit 941dc3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/13036.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add metrics measuring the CPU and DB time spent in state resolution.
12 changes: 12 additions & 0 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,15 @@ class _StateResMetrics:
"expensive room for state resolution",
)

_cpu_times = Histogram(
"synapse_state_res_cpu_for_all_rooms_seconds",
"CPU time (utime+stime) spent computing a single state resolution",
)
_db_times = Histogram(
"synapse_state_res_db_for_all_rooms_seconds",
"Database time spent computing a single state resolution",
)


class StateResolutionHandler:
"""Responsible for doing state conflict resolution.
Expand Down Expand Up @@ -609,6 +618,9 @@ def _record_state_res_metrics(
room_metrics.db_time += rusage.db_txn_duration_sec
room_metrics.db_events += rusage.evt_db_fetch_count

_cpu_times.observe(rusage.ru_utime + rusage.ru_stime)
_db_times.observe(rusage.db_txn_duration_sec)

def _report_metrics(self) -> None:
if not self._state_res_metrics:
# no state res has happened since the last iteration: don't bother logging.
Expand Down

0 comments on commit 941dc3d

Please sign in to comment.