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