-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.py
More file actions
92 lines (73 loc) · 2.71 KB
/
benchmark.py
File metadata and controls
92 lines (73 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# benchmark.py - Aether Stress Tester
import socket
import time
import threading
import argparse
import sys
# Global Counters
successful_reqs = 0
failed_reqs = 0
running = True
def load_worker(target_ip, target_port):
global successful_reqs, failed_reqs, running
while running:
try:
# Full TCP Connection -> Request -> Response -> Close
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
s.connect((target_ip, target_port))
# Send HTTP Request to trigger the "Connection: close" logic in stack
s.sendall(b"GET / HTTP/1.1\r\nHost: benchmark\r\n\r\n")
# Read until close
while True:
data = s.recv(4096)
if not data: break
s.close()
successful_reqs += 1
except:
failed_reqs += 1
def run_benchmark(ip, port, threads, duration):
global running, successful_reqs, failed_reqs
print(f"[*] Benchmarking Aether at {ip}:{port}")
print(f"[*] Threads: {threads} | Duration: {duration}s")
print("-" * 50)
print(f"{'Time':<10} | {'CPS (Conn/sec)':<15} | {'Total Success':<15} | {'Errors':<10}")
print("-" * 50)
# Spawn Workers
worker_threads = []
for _ in range(threads):
t = threading.Thread(target=load_worker, args=(ip, port))
t.daemon = True
t.start()
worker_threads.append(t)
start_time = time.time()
last_check = start_time
last_count = 0
try:
while time.time() - start_time < duration:
time.sleep(1.0)
current_time = time.time()
elapsed = current_time - last_check
# Calculate instantaneous CPS
current_count = successful_reqs
delta = current_count - last_count
cps = delta / elapsed
print(f"{int(current_time - start_time):<10} | {cps:<15.1f} | {current_count:<15} | {failed_reqs:<10}")
last_count = current_count
last_check = current_time
except KeyboardInterrupt:
print("\n[!] Interrupted.")
running = False
print("-" * 50)
total_time = time.time() - start_time
print(f"[*] Final Score: {successful_reqs / total_time:.2f} Connections/Sec")
print(f"[*] Total Transferred: {successful_reqs} requests")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="192.168.1.2")
parser.add_argument("--port", type=int, default=80)
parser.add_argument("--threads", type=int, default=100)
parser.add_argument("--time", type=int, default=30)
args = parser.parse_args()
run_benchmark(args.ip, args.port, args.threads, args.time)