From c8b12a3a3ad44bbd0ab33b19d4f799d063b780fa Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 20 Jul 2022 17:56:06 +0100 Subject: [PATCH 1/2] Track DB txn times w/ two counters, not histogram By my reckoning, this should mean that each txn `desc` produces 2 time series, down from 17. If we don't like this, we could keep the histogram but configure it with coarser buckets. Closes #11081. --- synapse/storage/database.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/synapse/storage/database.py b/synapse/storage/database.py index ea672ff89e73..b394a6658b09 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -39,7 +39,7 @@ ) import attr -from prometheus_client import Histogram +from prometheus_client import Counter, Histogram from typing_extensions import Concatenate, Literal, ParamSpec from twisted.enterprise import adbapi @@ -76,7 +76,8 @@ sql_scheduling_timer = Histogram("synapse_storage_schedule_time", "sec") sql_query_timer = Histogram("synapse_storage_query_time", "sec", ["verb"]) -sql_txn_timer = Histogram("synapse_storage_transaction_time", "sec", ["desc"]) +sql_txn_count = Counter("synapse_storage_transaction_time_count", "sec", ["desc"]) +sql_txn_duration = Counter("synapse_storage_transaction_time_sum", "sec", ["desc"]) # Unique indexes which have been added in background updates. Maps from table name @@ -795,7 +796,8 @@ def new_transaction( self._current_txn_total_time += duration self._txn_perf_counters.update(desc, duration) - sql_txn_timer.labels(desc).observe(duration) + sql_txn_count.labels(desc).inc(1) + sql_txn_duration.labels(desc).inc(duration) async def runInteraction( self, From 490af3af887720701222d83773176fc20f4f5216 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 20 Jul 2022 18:24:02 +0100 Subject: [PATCH 2/2] Changelog --- changelog.d/13342.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13342.misc diff --git a/changelog.d/13342.misc b/changelog.d/13342.misc new file mode 100644 index 000000000000..ce9c816b9c1a --- /dev/null +++ b/changelog.d/13342.misc @@ -0,0 +1 @@ +When reporting metrics is enabled, use ~8x less data to describe DB transaction metrics.