summary refs log tree commit diff
path: root/synapse/storage/events.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-03-27 10:30:03 +0100
committerErik Johnston <erik@matrix.org>2018-03-27 10:57:35 +0100
commit3f49e131d9a31d5bf198f2aa6b102562b2e747d0 (patch)
tree7adb35ff9c49c2203632bf9fb2ffa18e46be80a9 /synapse/storage/events.py
parentfix typo (diff)
downloadsynapse-3f49e131d9a31d5bf198f2aa6b102562b2e747d0.tar.xz
Add counter metrics for calculating state delta
This will allow us to measure how often we calculate state deltas in
event persistence that we would have been able to calculate at the same
time we calculated the state for the event.
Diffstat (limited to '')
-rw-r--r--synapse/storage/events.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 85ce6bea1a..f3a362db20 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -52,6 +52,15 @@ persist_event_counter = metrics.register_counter("persisted_events")
 event_counter = metrics.register_counter(
     "persisted_events_sep", labels=["type", "origin_type", "origin_entity"]
 )
+state_delta_counter = metrics.register_counter(
+    "state_delta",
+)
+state_delta_single_event_counter = metrics.register_counter(
+    "state_delta_single_event",
+)
+state_delta_reuse_delta_counter = metrics.register_counter(
+    "state_delta_reuse_delta",
+)
 
 
 def encode_json(json_object):
@@ -368,7 +377,8 @@ class EventsStore(EventsWorkerStore):
                                 room_id, ev_ctx_rm, latest_event_ids
                             )
 
-                            if new_latest_event_ids == set(latest_event_ids):
+                            latest_event_ids = set(latest_event_ids)
+                            if new_latest_event_ids == latest_event_ids:
                                 # No change in extremities, so no change in state
                                 continue
 
@@ -389,6 +399,25 @@ class EventsStore(EventsWorkerStore):
                                 if all_single_prev_not_state:
                                     continue
 
+                            state_delta_counter.inc()
+                            if len(new_latest_event_ids) == 1:
+                                state_delta_single_event_counter.inc()
+
+                                # This is a fairly handwavey check to see if we could
+                                # have guessed what the delta would have been when
+                                # processing one of these events.
+                                # What we're interested in is if the latest extremities
+                                # were the same when we created the event as they are
+                                # now. We guess this by looking at the prev events and
+                                # checking if they match up, as when this server creates
+                                # a new event it will use the extremities as the prev
+                                # events.
+                                for ev, _ in ev_ctx_rm:
+                                    prev_event_ids = set(e for e, _ in ev.prev_events)
+                                    if latest_event_ids == prev_event_ids:
+                                        state_delta_reuse_delta_counter.inc()
+                                    break
+
                             logger.info(
                                 "Calculating state delta for room %s", room_id,
                             )