Initial commit: dpdk-ws-client source code
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
import socket, time, random, json, base64
|
||||
|
||||
latencies = []
|
||||
for run in range(10):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(5)
|
||||
|
||||
t0 = time.time()
|
||||
s.connect(('192.168.123.132', 8080))
|
||||
t_conn = time.time() - t0
|
||||
|
||||
key = base64.b64encode(bytes([random.randint(0,255) for _ in range(16)])).decode()
|
||||
req = (f'GET /ws HTTP/1.1\r\n'
|
||||
f'Host: 192.168.123.132:8080\r\n'
|
||||
f'Upgrade: websocket\r\n'
|
||||
f'Connection: Upgrade\r\n'
|
||||
f'Sec-WebSocket-Key: {key}\r\n'
|
||||
f'Sec-WebSocket-Version: 13\r\n'
|
||||
f'\r\n')
|
||||
s.sendall(req.encode())
|
||||
s.recv(4096)
|
||||
t_hs = time.time() - t0
|
||||
|
||||
msg = json.dumps({'action':'ping'})
|
||||
frame = bytearray([0x81, 0x80 | len(msg)])
|
||||
mk = bytes([random.randint(0,255) for _ in range(4)])
|
||||
frame.extend(mk)
|
||||
for i,b in enumerate(msg.encode()):
|
||||
frame.append(b ^ mk[i%4])
|
||||
t1 = time.time()
|
||||
s.sendall(bytes(frame))
|
||||
s.recv(4096)
|
||||
t_echo = time.time() - t1
|
||||
|
||||
cl = bytearray([0x88, 0x80, 0x00, 0x00, 0x00, 0x00])
|
||||
s.sendall(cl)
|
||||
s.close()
|
||||
|
||||
latencies.append((t_conn*1000, t_hs*1000, t_echo*1000))
|
||||
print(f' run{run+1}: connect={t_conn*1000:.2f}ms hs={t_hs*1000:.2f}ms echo={t_echo*1000:.2f}ms')
|
||||
time.sleep(0.15)
|
||||
|
||||
a_c = sum(x[0] for x in latencies)/10
|
||||
a_h = sum(x[1] for x in latencies)/10
|
||||
a_e = sum(x[2] for x in latencies)/10
|
||||
min_c = min(x[0] for x in latencies)
|
||||
min_h = min(x[1] for x in latencies)
|
||||
min_e = min(x[2] for x in latencies)
|
||||
max_c = max(x[0] for x in latencies)
|
||||
max_h = max(x[1] for x in latencies)
|
||||
max_e = max(x[2] for x in latencies)
|
||||
print(f'\nKernel TCP + C Server (10 runs):')
|
||||
print(f' connect: min={min_c:.2f}ms avg={a_c:.2f}ms max={max_c:.2f}ms')
|
||||
print(f' handshake: min={min_h:.2f}ms avg={a_h:.2f}ms max={max_h:.2f}ms')
|
||||
print(f' echo RTT: min={min_e:.2f}ms avg={a_e:.2f}ms max={max_e:.2f}ms')
|
||||
Reference in New Issue
Block a user