Skip to content

Commit

Permalink
[REVERT THIS] Track some metrics to see how big this gets
Browse files Browse the repository at this point in the history
  • Loading branch information
realtyem committed Sep 25, 2023
1 parent a114fd3 commit 7485521
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
"synapse_event_fetch_ongoing",
"The number of event fetchers that are running",
)
event_metadata_cache_size_gauge = Gauge(
"synapse_event_metadata_cache_size",
"The size of event metadata cache in number of entries",
)


class InvalidEventError(Exception):
Expand Down Expand Up @@ -329,6 +333,11 @@ def get_chain_id_txn(txn: Cursor) -> int:

self._un_partial_stated_events_stream_id_gen: AbstractStreamIdGenerator

# This is a crap way to track metrics, but will do for this experiment.
self.track_metadata_size_loop = self._clock.looping_call(
self.track_metadata_size, 1000
)

if isinstance(database.engine, PostgresEngine):
self._un_partial_stated_events_stream_id_gen = MultiWriterIdGenerator(
db_conn=db_conn,
Expand All @@ -351,6 +360,13 @@ def get_chain_id_txn(txn: Cursor) -> int:
"stream_id",
)

def track_metadata_size(self) -> None:
# Get the total number of entries
size = len(self._event_metadata)
for room_id in self._event_metadata:
size += len(self._event_metadata[room_id].events)
event_metadata_cache_size_gauge.set(size)

def get_un_partial_stated_events_token(self, instance_name: str) -> int:
return (
self._un_partial_stated_events_stream_id_gen.get_current_token_for_writer(
Expand Down

0 comments on commit 7485521

Please sign in to comment.