Blame SOURCES/sos-bz1733352-cmd-poll-performance.patch

5baea9
From 3253179b207c2616ce238e2bb765635fe59e6dd2 Mon Sep 17 00:00:00 2001
5baea9
From: Kazuhito Hagio <k-hagio@ab.jp.nec.com>
5baea9
Date: Thu, 18 Jul 2019 09:58:56 -0400
5baea9
Subject: [PATCH] [utilities] Fix high CPU usage and slow command collection
5baea9
5baea9
commit fc6721ac83c2 ("[Plugin] Terminate running commands when a plugin
5baea9
exceeds timeout") introduced a polling method to sos_get_command_output()
5baea9
but it is busy wait, and seems to increase the CPU usage and slow down
5baea9
AsyncReader significantly.
5baea9
5baea9
As a result, a command that outputs much data like journalctl takes
5baea9
longer time, and the plugin times out.
5baea9
5baea9
Inserting a sleep is a possible fix for this.
5baea9
5baea9
Resolves: #1732
5baea9
5baea9
Signed-off-by: Kazuhito Hagio <k-hagio@ab.jp.nec.com>
5baea9
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
5baea9
---
5baea9
 sos/utilities.py | 4 +++-
5baea9
 1 file changed, 3 insertions(+), 1 deletion(-)
5baea9
5baea9
diff --git a/sos/utilities.py b/sos/utilities.py
5baea9
index 1737478f..c3d6ac20 100644
5baea9
--- a/sos/utilities.py
5baea9
+++ b/sos/utilities.py
5baea9
@@ -18,6 +18,7 @@ import errno
5baea9
 import shlex
5baea9
 import glob
5baea9
 import threading
5baea9
+import time
5baea9
 
5baea9
 from contextlib import closing
5baea9
 from collections import deque
5baea9
@@ -158,6 +159,7 @@ def sos_get_command_output(command, timeout=300, stderr=False,
5baea9
                 if poller():
5baea9
                     p.terminate()
5baea9
                     raise SoSTimeoutError
5baea9
+                time.sleep(0.01)
5baea9
         stdout = reader.get_contents()
5baea9
         while p.poll() is None:
5baea9
             pass
5baea9
@@ -248,7 +250,7 @@ class AsyncReader(threading.Thread):
5baea9
         # block until command completes or timesout (separate from the plugin
5baea9
         # hitting a timeout)
5baea9
         while self.running:
5baea9
-            pass
5baea9
+            time.sleep(0.01)
5baea9
         if not self.binary:
5baea9
             return ''.join(ln.decode('utf-8', 'ignore') for ln in self.deque)
5baea9
         else:
5baea9
-- 
5baea9
2.21.0
5baea9