Constant time

This commit is contained in:
Pascal Engélibert 2026-03-13 14:58:15 +01:00
commit 7ae94371a8
5 changed files with 81 additions and 24 deletions

1
.gitignore vendored
View file

@ -2,5 +2,4 @@
netreplay* netreplay*
powercap powercap
__pycache__ __pycache__
rpxy_*
records/ records/

View file

@ -333,7 +333,7 @@ Install OpenSSL with debug symbols:
/usr/bin/perl ./Configure --release -g --prefix=/usr --openssldir=/usr/lib/ssl --libdir=lib/x86_64-linux-gnu shared no-idea no-mdc2 no-rc5 no-ssl3 no-ssl3-method enable-rfc3779 enable-cms no-capieng no-rdrand enable-zlib enable-ec_nistp_64_gcc_128 linux-x86_64 /usr/bin/perl ./Configure --release -g --prefix=/usr --openssldir=/usr/lib/ssl --libdir=lib/x86_64-linux-gnu shared no-idea no-mdc2 no-rc5 no-ssl3 no-ssl3-method enable-rfc3779 enable-cms no-capieng no-rdrand enable-zlib enable-ec_nistp_64_gcc_128 linux-x86_64
``` ```
To build rpxy with this openssl: To build netreplay with this openssl:
```bash ```bash
OPENSSL_LIB_DIR=/home/pi/reps/openssl-openssl-3.6.0/ OPENSSL_DIR=/home/pi/reps/openssl-openssl-3.6.0/ cargo build --release OPENSSL_LIB_DIR=/home/pi/reps/openssl-openssl-3.6.0/ OPENSSL_DIR=/home/pi/reps/openssl-openssl-3.6.0/ cargo build --release

36
exp.py
View file

@ -87,7 +87,7 @@ CONFIGS = {
True, True,
], ],
"records": [ "records": [
{ "filename": "wikipedia", "repeat": 1000 }, { "filename": "wikipedia", "repeat": 10000, "time": 90 },
], ],
"repo_dir": "/home/tuxmain/reps/tlsbench", "repo_dir": "/home/tuxmain/reps/tlsbench",
"exp_dir": "/dev/shm/exp", "exp_dir": "/dev/shm/exp",
@ -102,7 +102,7 @@ CONFIGS = {
"rapl": False, "rapl": False,
"sa": True, "sa": True,
"listen_port": 8080, "listen_port": 8080,
"idle": "idle - - - - - - - - - 600.000081539154 0.0 896 4792 0.5399999999999991 0 -", "idle": "idle - - - - - - - - - - - 600.000081539154 0.0 896 4792 0.5399999999999991 0 -",
"notify_listen": ("0.0.0.0", 8090), "notify_listen": ("0.0.0.0", 8090),
"notify_addr": "192.168.3.1:8090", "notify_addr": "192.168.3.1:8090",
}, },
@ -245,10 +245,11 @@ CONFIGS = {
}, },
"g5k": { "g5k": {
"experiments": [ "experiments": [
"impl-cipher-ver", #"impl-cipher-ver",
"impl-cert-ver", #"impl-cert-ver",
"impl-kex-ver", #"impl-kex-ver",
"zrtt", #"zrtt",
"realistic",
], ],
"sides": [ "sides": [
"client", "client",
@ -259,7 +260,7 @@ CONFIGS = {
True, True,
], ],
"records": [ "records": [
{ "filename": "wikipedia", "repeat": 12000 }, { "filename": "wikipedia", "repeat": 12000, "time": 60 },
], ],
"repo_dir": "/home/pengelib/tlsbench", "repo_dir": "/home/pengelib/tlsbench",
"exp_dir": "/dev/shm/exp", "exp_dir": "/dev/shm/exp",
@ -638,7 +639,9 @@ def run_netreplay_client(ssh, exp_dir, repo_dir, record, remote_addr, remote_por
env["CIPHERS"] = ciphers env["CIPHERS"] = ciphers
if kexes: if kexes:
env["KEXES"] = kexes env["KEXES"] = kexes
cmd = [repo_dir+"/netreplay"+("" if impl == None else ("-"+impl)), repo_dir+"/records/"+record["filename"], "client", remote_addr, str(remote_port), "-r", str(record["repeat"]), "--certs", certs_dir] cmd = [repo_dir+"/netreplay"+("" if impl == None else ("-"+impl)), repo_dir+"/records/"+record["filename"], "client", remote_addr, str(remote_port), "--certs", certs_dir]
if "repeat" in record:
cmd += ["-r", str(record["repeat"])]
if debug: if debug:
cmd.append("-d") cmd.append("-d")
if tls: if tls:
@ -911,7 +914,7 @@ def run_exp(config, only_record=None, idle=False, shutdown=False, debug=False):
# Measure # Measure
cpu = 0 cpu = 0
if config["sa"]: if config["sa"]:
cpu = get_cpu_stat(ssh, ["netreplay-"+impl, "tokio-runtime-w"]) cpu = get_cpu_stat(ssh, ["netreplay-"+impl, "tokio-runtime-w", "tokio-rt-worker"])
remote_bytes_in, remote_bytes_out = get_net_stat(ssh) remote_bytes_in, remote_bytes_out = get_net_stat(ssh)
energy = 0 energy = 0
energy_rapl = 0 energy_rapl = 0
@ -922,9 +925,15 @@ def run_exp(config, only_record=None, idle=False, shutdown=False, debug=False):
start = time.time() start = time.time()
# Wait for the client to terminate # Wait for the client to terminate
signal.alarm(3600) signal.alarm(record["time"] if "time" in record else 3600)
session_count = 0
try: try:
notify_socket.recv(4) while True:
rec_count = int.from_bytes(notify_socket.recv(4))
if rec_count == 0xffffffff:
break
if rec_count > session_count:
session_count = rec_count
except Timeout: except Timeout:
print("TIMEOUT: stop") print("TIMEOUT: stop")
@ -953,7 +962,7 @@ def run_exp(config, only_record=None, idle=False, shutdown=False, debug=False):
# Measure CPU after (as it may update only after the process is killed) # Measure CPU after (as it may update only after the process is killed)
new_cpu = 0 new_cpu = 0
if config["sa"]: if config["sa"]:
new_cpu = get_cpu_stat(ssh, ["netreplay-"+impl, "tokio-runtime-w"]) new_cpu = get_cpu_stat(ssh, ["netreplay-"+impl, "tokio-runtime-w", "tokio-rt-worker"])
record_filename = record["filename"] record_filename = record["filename"]
cpu_diff = new_cpu - cpu cpu_diff = new_cpu - cpu
@ -962,11 +971,10 @@ def run_exp(config, only_record=None, idle=False, shutdown=False, debug=False):
energy_diff = new_energy - energy energy_diff = new_energy - energy
energy_rapl_diff = new_energy_rapl - energy_rapl energy_rapl_diff = new_energy_rapl - energy_rapl
time_diff = end - start time_diff = end - start
repeats = record["repeat"]
while True: while True:
try: try:
with open(logfile_path, "a") as logfile: with open(logfile_path, "a") as logfile:
logfile.write(f"{expname} {impl} {alg} {kex} {cipher} {earlydata} {side} {tls_int} {record_filename} {repeats} {start} {end} {time_diff} {cpu_diff} {remote_bytes_in_diff} {remote_bytes_out_diff} {energy_diff} {energy_rapl_diff} {prof_filename}\n") logfile.write(f"{expname} {impl} {alg} {kex} {cipher} {earlydata} {side} {tls_int} {record_filename} {session_count} {start} {end} {time_diff} {cpu_diff} {remote_bytes_in_diff} {remote_bytes_out_diff} {energy_diff} {energy_rapl_diff} {prof_filename}\n")
logfile.close() logfile.close()
break break
except Exception as e: except Exception as e:

View file

@ -483,6 +483,62 @@ def cmp_versions(logs, exps, criteria, objs):
except ZeroDivisionError: except ZeroDivisionError:
pass pass
def tabulate(lines):
widths = [0] * len(lines[0])
for line in lines:
for col in range(len(line)):
if len(line[col]) > widths[col]:
widths[col] = len(line[col])
table = ""
for line in lines:
for col in range(len(line)):
if col > 0:
table += " "
table += line[col]
table += " " * (widths[col] - len(line[col]))
table += "\n"
return table
def make_summary(logs):
plain_result_key = lambda log: (log["exp"], log["side"])
result_key = lambda log: (log["exp"], log["side"], log["impl"], log["alg"], log["kex"], log["cipher"], log["ed"])
plain_results = {}
results = {}
idle_val = None
for log in logs:
if log["exp"] == "idle":
idle_val = {
"cpu": float(log["cpu"]) / float(log["time"]),
"energy": float(log["Wh"]) / float(log["time"]) * 3600,
}
if log["tls"] == "0":
n = float(log.get("n", "1000"))
plain_results[plain_result_key(log)] = {
"cpu": (float(log["cpu"]) - idle_val["cpu"] * float(log["time"])) / n,
"energy": (float(log["Wh"]) * 3600 - idle_val["energy"] * float(log["time"])) / n
}
if log["exp"] != "idle" and log["tls"] == "1":
n = float(log.get("n", "1000"))
results[result_key(log)] = {
"cpu": (float(log["cpu"]) - idle_val["cpu"] * float(log["time"])) / n,
"energy": (float(log["Wh"]) * 3600 - idle_val["energy"] * float(log["time"])) / n
}
lines = [["key", "idle (W)", "no_tls (Ws/S)", "tls (Ws/S)", "tls_only (1)"]]
for k in results:
no_tls = plain_results[k[:2]]["energy"]
tls = results[k]["energy"]
lines.append([
"/".join([str(i) for i in k]),
str(idle_val["energy"]),
str(no_tls),
str(tls),
str((tls - no_tls) / tls),
])
print(tabulate(lines))
def getargv(arg:str, default="", n:int=1, args:list=sys.argv): def getargv(arg:str, default="", n:int=1, args:list=sys.argv):
if arg in args and len(args) > args.index(arg)+n: if arg in args and len(args) > args.index(arg)+n:
return args[args.index(arg)+n] return args[args.index(arg)+n]
@ -537,6 +593,8 @@ if __name__ == "__main__":
make_profile_plot_grouped(logs, "impl-cipher-ver", "cipher", side, record, "impl", no_flamegraph=no_flamegraph, machine=machine, maketitle=maketitle, version="1.3") make_profile_plot_grouped(logs, "impl-cipher-ver", "cipher", side, record, "impl", no_flamegraph=no_flamegraph, machine=machine, maketitle=maketitle, version="1.3")
make_profile_plot_grouped(logs, "impl-cert-ver", "cert", side, record, "impl", no_flamegraph=no_flamegraph, machine=machine, maketitle=maketitle, version="1.3") make_profile_plot_grouped(logs, "impl-cert-ver", "cert", side, record, "impl", no_flamegraph=no_flamegraph, machine=machine, maketitle=maketitle, version="1.3")
make_profile_plot_grouped(logs, "impl-kex-ver", "kex", side, record, "impl", no_flamegraph=no_flamegraph, machine=machine, maketitle=maketitle, version="1.3") make_profile_plot_grouped(logs, "impl-kex-ver", "kex", side, record, "impl", no_flamegraph=no_flamegraph, machine=machine, maketitle=maketitle, version="1.3")
elif cmd == "summary":
make_summary(logs)
elif cmd == "correl": elif cmd == "correl":
from scipy import stats from scipy import stats
import matplotlib.pyplot as plt import matplotlib.pyplot as plt

8
run.sh
View file

@ -1,8 +0,0 @@
#kissdns kissdns.json 5532
RUST_LOG=debug ./rpxy_rustls_ring --config experiments/p1_tls.toml &
RUST_LOG=debug ./rpxy_rustls_ring --config experiments/p2_tls.toml &
RUST_LOG=debug ./rpxy_rustls_ring --config experiments/p3.toml &
# By default, ^C does not kill subprocesses. This fixes it.
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
wait