Have fedabipkgdiff sleep while waiting for abipkgdiff
authorBen Woodard <woodard@redhat.com>
Tue, 28 Mar 2023 19:52:28 +0000 (12:52 -0700)
committerDodji Seketeli <dodji@redhat.com>
Fri, 31 Mar 2023 20:48:18 +0000 (22:48 +0200)
While running tests, I noticed that python was consuming a huge amount
of CPU. Frank Eigler located the problem and pointed
out that python was continiously polling for abipkgdiff's
completion. For small packages, the time to completion can be less
than a second but some packages can take literally hours to
analyze. Having python spinning in such a tight loop is unnecessary. I
added a small sleep to this loop with a bit of backoff. Vanessa Sochat
helped with examples of how to fix the python code.

* tools/fedabipkgdiff (abipkgdiff): add sleep while waiting for
subprocess completion. Also, update copyright year notice to 2023.

Signed-off-by: Ben Woodard <woodard@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
tools/fedabipkgdiff

index db23d5a3fdda8888c3d35d535529d3c20ccf411d..86bf0048beb4d75b0679bca23aa17e797d7993cc 100755 (executable)
@@ -3,7 +3,7 @@
 # -*- coding: utf-8 -*-
 # -*- Mode: Python
 #
-# Copyright (C) 2013-2016 Red Hat, Inc.
+# Copyright (C) 2013-2023 Red Hat, Inc.
 #
 # Author: Chenxiong Qi
 
@@ -20,6 +20,7 @@ import shutil
 import six
 import subprocess
 import sys
+import time
 
 from collections import namedtuple
 from itertools import chain
@@ -1187,9 +1188,14 @@ def abipkgdiff(cmp_half1, cmp_half2):
     # then we get its output.
     #
 
+    sleeptime = 0.2
     while True:
         if proc.poll() != None:
             break
+        time.sleep(sleeptime)
+        # cap the sleep time at 1.6s
+        if sleeptime < 2.0:
+            sleeptime = sleeptime * 2
 
     stdout = ''.join(proc.stdout.readlines())
     stderr = ''.join(proc.stderr.readlines())