From d115bfd72a61f23bba0eb5d2d82c2ad94eac15e2 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 31 Jul 2023 07:04:34 -0700 Subject: [PATCH] Reduce the flush frequency of dbcounter plugin This relaxes the limits for dbcounter to make it flush stats to the database less often. Currently every thirty seconds or 100 hits, we write a stats line to the database. In some services (like keystone) this can trigger more than one write per second because of the massive number of SELECT calls that service makes. This removes the hit limit and decreases the mandatory flush interval to once a minute. Hopefully this will manifest as lower load on the database triggered by what would be readonly operations. Change-Id: I43a58532c0541075a2d36408abc50a41f7994bda --- tools/dbcounter/dbcounter.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/dbcounter/dbcounter.py b/tools/dbcounter/dbcounter.py index 0ed7bb813a..86e5529c97 100644 --- a/tools/dbcounter/dbcounter.py +++ b/tools/dbcounter/dbcounter.py @@ -96,20 +96,18 @@ class LogCursorEventsPlugin(CreateEnginePlugin): This reads "hists" from from a queue fed by _log_event() and writes (db,op)+=count stats to the database after ten seconds of no activity to avoid triggering a write for every SELECT - call. Write no less often than every thirty seconds and/or 100 - pending hits to avoid being starved by constant activity. + call. Write no less often than every sixty seconds to avoid being + starved by constant activity. """ LOG.debug('[%i] Writer thread running' % os.getpid()) while True: to_write = {} - total = 0 last = time.time() - while time.time() - last < 30 and total < 100: + while time.time() - last < 60: try: item = self.queue.get(timeout=10) to_write.setdefault(item, 0) to_write[item] += 1 - total += 1 except queue.Empty: break