aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuhito Hagio <k-hagio@ab.jp.nec.com>2019-07-18 09:58:56 -0400
committerBryn M. Reeves <bmr@redhat.com>2019-07-29 18:45:18 +0100
commit3253179b207c2616ce238e2bb765635fe59e6dd2 (patch)
tree9600f523ba53f9a0474817b8367d8a376154b9c1
parentb5d72bd91c8685e3551d6e796ca8559304b45785 (diff)
downloadsos-3253179b207c2616ce238e2bb765635fe59e6dd2.tar.gz
[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 <k-hagio@ab.jp.nec.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/utilities.py4
1 files changed, 3 insertions, 1 deletions
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: