Skip to content

Instantly share code, notes, and snippets.

@tejom
Created November 17, 2022 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tejom/a6ea16759c78dc7f409c2a4ba47d1ba0 to your computer and use it in GitHub Desktop.
Save tejom/a6ea16759c78dc7f409c2a4ba47d1ba0 to your computer and use it in GitHub Desktop.
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