Skip to content
Snippets Groups Projects
Commit 33822835 authored by Michael Eischer's avatar Michael Eischer
Browse files

Parallelize ping measurements

parent 6ccb1fdd
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import argparse
import subprocess
from typing import Sequence
from concurrent.futures.thread import ThreadPoolExecutor
from typing import Sequence, Tuple
from benchmark import GenericTestRun, main
......@@ -17,24 +18,41 @@ class MeasureServerPings(GenericTestRun):
def setup_args(cls, parser: argparse.ArgumentParser) -> None:
parser.add_argument("duration", help="Duration of the test run", type=int)
def stage_build(self) -> bool:
# Nothing to do for this test
return True
def _ping(self, src, dst) -> Tuple[str, int]:
ssh = self.start_ssh(self.config["remote.user"], src, "ping", "-c", str(self.duration), dst,
stdout=subprocess.PIPE)
(output, _) = ssh.communicate()
log = "=== Ping from {} to {} ===".format(src, dst)
if ssh.returncode != 0:
log += "\nMeasurement error {}".format(ssh.returncode)
return log, ssh.returncode
for line in output.decode("utf-8").splitlines():
if "rtt min/avg/max/mdev" in line:
log += "\n" + line
return log, 0
def stage_bench(self) -> bool:
servers = self.get_servers(("client.network.addresses", "replica.network.addresses"))
for (i, dst) in enumerate(servers):
for j in range(i + 1, len(servers)):
src = servers[j]
self.log("=== Ping from {} to {} ===".format(src, dst))
ssh = self.start_ssh(self.config["remote.user"], src, "ping", "-c", str(self.duration), dst,
stdout=subprocess.PIPE)
(output, _) = ssh.communicate()
if ssh.returncode != 0:
self.log("Measurement error {}".format(ssh.returncode))
with ThreadPoolExecutor(max_workers=30) as executor:
results = []
for (i, dst) in enumerate(servers):
for j in range(i + 1, len(servers)):
src = servers[j]
res = executor.submit(self._ping, src, dst)
results.append(res)
for res in results:
r = res.result()
self.log(r[0])
if r[1] != 0:
return False
for line in output.decode("utf-8").splitlines():
if "rtt min/avg/max/mdev" in line:
self.log(line)
return True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment