-
-
Save tejom/a6ea16759c78dc7f409c2a4ba47d1ba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
import numpy | |
from threading import Thread | |
times = [] | |
def run(): | |
try: | |
_run() | |
except (Exception, KeyboardInterrupt): | |
return | |
def _run(): | |
print("start") | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server_address = ('localhost', 8080) | |
sock.connect(server_address) | |
while True: | |
now = time.time() | |
message = b'test data' | |
sock.sendall(message) | |
amount_received = 0 | |
amount_expected = len(message) | |
while amount_received < amount_expected: | |
data = sock.recv(1024) | |
amount_received += len(data) | |
diff = time.time() - now | |
times.append(diff) | |
try: | |
th = [] | |
for i in range(0, 4): | |
t = Thread(target=run) | |
t.daemon = True | |
t.start() | |
th.append(t) | |
for t in th: | |
t.join() | |
except (Exception, KeyboardInterrupt): | |
total = len(times) | |
print(f"total {total}") | |
print(numpy.percentile(times, [50, 99, 99.9])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment