diff options
author | Erik Johnston <erik@matrix.org> | 2016-05-09 10:13:25 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-05-09 10:13:25 +0100 |
commit | 1f1dee94f6025ce0a6e414cd6098cb766567bdd8 (patch) | |
tree | 8896c4d076794fc19135f9ac98675460cf09dcc6 | |
parent | Merge pull request #767 from matrix-org/erikj/transaction_txn (diff) | |
download | synapse-1f1dee94f6025ce0a6e414cd6098cb766567bdd8.tar.xz |
Manually run GC on reactor tick.
This also adds a metric for amount of time spent in GC.
Diffstat (limited to '')
-rw-r--r-- | synapse/metrics/__init__.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/synapse/metrics/__init__.py b/synapse/metrics/__init__.py index 5664d5a381..17be491b93 100644 --- a/synapse/metrics/__init__.py +++ b/synapse/metrics/__init__.py @@ -22,6 +22,7 @@ import functools import os import stat import time +import gc from twisted.internet import reactor @@ -155,6 +156,7 @@ get_metrics_for("process").register_callback("fds", _process_fds, labels=["type" reactor_metrics = get_metrics_for("reactor") tick_time = reactor_metrics.register_distribution("tick_time") pending_calls_metric = reactor_metrics.register_distribution("pending_calls") +gc_time = reactor_metrics.register_distribution("gc_time") def runUntilCurrentTimer(func): @@ -182,6 +184,18 @@ def runUntilCurrentTimer(func): end = time.time() * 1000 tick_time.inc_by(end - start) pending_calls_metric.inc_by(num_pending) + + threshold = gc.get_threshold() + counts = gc.get_count() + + start = time.time() * 1000 + for i in [2, 1, 0]: + if threshold[i] < counts[i]: + logger.info("Collecting gc %d", i) + gc.collect(i) + end = time.time() * 1000 + gc_time.inc_by(end - start) + return ret return f @@ -196,5 +210,6 @@ try: # runUntilCurrent is called when we have pending calls. It is called once # per iteratation after fd polling. reactor.runUntilCurrent = runUntilCurrentTimer(reactor.runUntilCurrent) + gc.disable() except AttributeError: pass |