bench: run rsync over localhost network for fair comparison

Previously rsync ran as a direct local copy (rsync -aH source/ dest/), bypassing the
loopback interface entirely. This meant tc netem latency/loss/rate limits were never
applied to rsync, making the comparison fundamentally unfair.

Now rsync goes through the network via an rsync daemon on localhost:
  rsync --daemon --no-detach --config=rsyncd.conf
  rsync rsync://localhost:PORT/source/ dest/

The daemon is started before rsync tests and killed afterward. Both the rsync client
and FastSync client run under the same systemd-run disk I/O limits when applicable.
This commit is contained in:
2026-07-05 16:58:13 +02:00
parent 7a1c491f7f
commit 5170155112
+43 -2
View File
@@ -6,6 +6,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import time import time
import socket
TEST_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_data") TEST_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_data")
DEFAULT_SOURCE_DIR = os.path.join(TEST_DIR, "source") DEFAULT_SOURCE_DIR = os.path.join(TEST_DIR, "source")
@@ -86,6 +87,12 @@ def netem_reset():
) )
def find_free_port():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 0))
return s.getsockname()[1]
def generate_test_files(source_dir): def generate_test_files(source_dir):
if os.path.exists(source_dir): if os.path.exists(source_dir):
shutil.rmtree(source_dir) shutil.rmtree(source_dir)
@@ -262,6 +269,27 @@ def run_profile(profile_name, source_dir, dest_dir):
server_process.kill() server_process.kill()
server_process.wait() server_process.wait()
# Rsync tests (over network via daemon, so tc netem applies)
rsync_port = find_free_port()
rsyncd_conf = os.path.join(tempfile.gettempdir(), f"rsyncd-{rsync_port}.conf")
with open(rsyncd_conf, "w") as f:
f.write(f"""use chroot = no
max connections = 5
read only = yes
port = {rsync_port}
[source]
path = {source_dir}
""")
rsync_daemon = None
try:
rsync_daemon = subprocess.Popen(
["rsync", "--daemon", "--no-detach", f"--config={rsyncd_conf}"],
stdout=subprocess.DEVNULL, stderr=None
)
time.sleep(0.5)
for case in RSYNC_CASES: for case in RSYNC_CASES:
name = case["name"] name = case["name"]
rsync_args = case["args"] rsync_args = case["args"]
@@ -272,9 +300,10 @@ def run_profile(profile_name, source_dir, dest_dir):
try: try:
rsync_cmd = ( rsync_cmd = (
["rsync"] client_prefix
+ ["rsync"]
+ rsync_args + rsync_args
+ [f"{source_dir}/", f"{dest_dir}/"] + [f"rsync://localhost:{rsync_port}/source/", f"{dest_dir}/"]
) )
print(f" Running: {' '.join(rsync_cmd)}") print(f" Running: {' '.join(rsync_cmd)}")
@@ -321,6 +350,18 @@ def run_profile(profile_name, source_dir, dest_dir):
{"name": name, "suite": profile_name, "status": "Error", "time": "N/A", "error": str(e)} {"name": name, "suite": profile_name, "status": "Error", "time": "N/A", "error": str(e)}
) )
finally:
if rsync_daemon:
try:
rsync_daemon.wait(timeout=5)
except subprocess.TimeoutExpired:
rsync_daemon.kill()
rsync_daemon.wait()
try:
os.unlink(rsyncd_conf)
except Exception:
pass
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(f" Error running netem command: {' '.join(e.cmd)}") print(f" Error running netem command: {' '.join(e.cmd)}")
finally: finally: