From 00ff6879f98efdd9d52564f8c6d5210020fbc4ec Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 30 Jan 2018 18:00:23 +0100 Subject: [PATCH] metricd: remove janitor process This merge the janitor process in the worker 0 of the metric processor. This saves some megabytes of memory. Closes #652 --- gnocchi/cli/metricd.py | 22 +++++++++------------- gnocchi/opts.py | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gnocchi/cli/metricd.py b/gnocchi/cli/metricd.py index 36da079af..1a679cf5c 100644 --- a/gnocchi/cli/metricd.py +++ b/gnocchi/cli/metricd.py @@ -148,6 +148,9 @@ def __init__(self, worker_id, conf): self._get_sacks_to_process = cachetools.func.ttl_cache( ttl=conf.metricd.metric_processing_delay )(self._get_sacks_to_process) + if worker_id == 0: + self.name = "processing+janitor" + self._last_expunge = utils.StopWatch().start() @tenacity.retry( wait=utils.wait_exponential, @@ -217,6 +220,12 @@ def _get_sacks_to_process(self): return self._tasks or self.fallback_tasks def _run_job(self): + if (self.worker_id == 0 and + self._last_expunge.elapsed() + >= self.conf.metric.metric_cleanup_delay): + self.store.expunge_metrics(self.incoming, self.index) + self._last_expunge.reset() + m_count = 0 s_count = 0 # We are going to process the sacks we got notified for, and if we got @@ -258,18 +267,6 @@ def close_services(self): self.coord.stop() -class MetricJanitor(MetricProcessBase): - name = "janitor" - - def __init__(self, worker_id, conf): - super(MetricJanitor, self).__init__( - worker_id, conf, conf.metricd.metric_cleanup_delay) - - def _run_job(self): - self.store.expunge_metrics(self.incoming, self.index) - LOG.debug("Metrics marked for deletion removed from backend") - - class MetricdServiceManager(cotyledon.ServiceManager): def __init__(self, conf): super(MetricdServiceManager, self).__init__() @@ -281,7 +278,6 @@ def __init__(self, conf): workers=conf.metricd.workers) if self.conf.metricd.metric_reporting_delay >= 0: self.add(MetricReporting, args=(self.conf,)) - self.add(MetricJanitor, args=(self.conf,)) self.register_hooks(on_reload=self.on_reload) diff --git a/gnocchi/opts.py b/gnocchi/opts.py index 752508387..74a6bf692 100644 --- a/gnocchi/opts.py +++ b/gnocchi/opts.py @@ -153,7 +153,7 @@ def list_opts(): deprecated_group='storage', default=300, required=True, - help="How many seconds to wait between " + help="How many seconds to wait (at least) between " "cleaning of expired data"), cfg.IntOpt('processing_replicas', default=3,