Change in osmo-gsm-tester[master]: process: Speed-up terminating lots of processes by batching it

Holger Freyther gerrit-no-reply at lists.osmocom.org
Mon Mar 4 07:43:13 UTC 2019


Holger Freyther has submitted this change and it was merged. ( https://gerrit.osmocom.org/13085 )

Change subject: process: Speed-up terminating lots of processes by batching it
......................................................................

process: Speed-up terminating lots of processes by batching it

Introduce a strategy to terminate processes and begin with an
implementation for parallel (that has no degree of parallelism
right now).

Change-Id: I7dd4a7e26aca758198aa08a434eaf5f3f5af632d
---
M src/osmo_gsm_tester/process.py
M src/osmo_gsm_tester/suite.py
2 files changed, 38 insertions(+), 10 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, but someone else must approve
  Pau Espin Pedrol: Looks good to me, approved



diff --git a/src/osmo_gsm_tester/process.py b/src/osmo_gsm_tester/process.py
index b1769f8..1e53aba 100644
--- a/src/osmo_gsm_tester/process.py
+++ b/src/osmo_gsm_tester/process.py
@@ -21,12 +21,38 @@
 import time
 import subprocess
 import signal
+from abc import ABCMeta, abstractmethod
 from datetime import datetime
 
 from . import log
 from .event_loop import MainLoop
 from .util import Dir
 
+class TerminationStrategy(log.Origin, metaclass=ABCMeta):
+    """A baseclass for terminating a collection of processes."""
+
+    def __init__(self):
+        self._processes = []
+
+    def add_process(self, process):
+        """Remembers a process that needs to be terminated."""
+        self._processes.append(process)
+
+    @abstractmethod
+    def terminate_all(self):
+        "Terminates all scheduled processes and waits for the termination."""
+        pass
+
+
+class ParallelTerminationStrategy(TerminationStrategy):
+    """Processes will be terminated in parallel."""
+
+    def terminate_all(self):
+        # TODO(zecke): Actually make this non-sequential.
+        for process in self._processes:
+            process.terminate()
+
+
 class Process(log.Origin):
 
     def __init__(self, name, run_dir, popen_args, **popen_kwargs):
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index e5ac9a8..39da917 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -23,7 +23,7 @@
 import pprint
 from . import config, log, util, resource, test
 from .event_loop import MainLoop
-from . import osmo_nitb, osmo_hlr, osmo_mgcpgw, osmo_mgw, osmo_msc, osmo_bsc, osmo_stp, osmo_ggsn, osmo_sgsn, modem, esme, osmocon, ms_driver, iperf3
+from . import osmo_nitb, osmo_hlr, osmo_mgcpgw, osmo_mgw, osmo_msc, osmo_bsc, osmo_stp, osmo_ggsn, osmo_sgsn, modem, esme, osmocon, ms_driver, iperf3, process
 
 class Timeout(Exception):
     pass
@@ -246,9 +246,11 @@
         self._processes.insert(0, (process, respawn))
 
     def stop_processes(self):
+        strategy = process.ParallelTerminationStrategy()
         while self._processes:
-            process, respawn = self._processes.pop()
-            process.terminate()
+            proc, _ = self._processes.pop()
+            strategy.add_process(proc)
+        strategy.terminate_all()
 
     def stop_process(self, process):
         'Remove process from monitored list and stop it'
@@ -382,15 +384,15 @@
 
     def poll(self):
         if self._processes:
-            for process, respawn in self._processes:
-                if process.terminated():
+            for proc, respawn in self._processes:
+                if proc.terminated():
                     if respawn == True:
-                        process.respawn()
+                        proc.respawn()
                     else:
-                        process.log_stdout_tail()
-                        process.log_stderr_tail()
-                        log.ctx(process)
-                        raise log.Error('Process ended prematurely: %s' % process.name())
+                        proc.log_stdout_tail()
+                        proc.log_stderr_tail()
+                        log.ctx(proc)
+                        raise log.Error('Process ended prematurely: %s' % proc.name())
 
     def prompt(self, *msgs, **msg_details):
         'ask for user interaction. Do not use in tests that should run automatically!'

-- 
To view, visit https://gerrit.osmocom.org/13085
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7dd4a7e26aca758198aa08a434eaf5f3f5af632d
Gerrit-Change-Number: 13085
Gerrit-PatchSet: 2
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190304/ffba2cfc/attachment.html>


More information about the gerrit-log mailing list