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