Demo multi-clients
This commit is contained in:
parent
6a0a12d6ae
commit
07b171cfc4
1 changed files with 51 additions and 0 deletions
51
demo_multi_client.py
Normal file
51
demo_multi_client.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import socket
|
||||
import time
|
||||
import threading
|
||||
|
||||
from coapthon.client.helperclient import HelperClient
|
||||
from coapthon.client.superviseur_local import SuperviseurLocal, SuperviseurLocalFiltre
|
||||
from coapthon.utils import parse_uri
|
||||
|
||||
N_rep = 100
|
||||
N_client = 25
|
||||
|
||||
host, port, path = parse_uri("coap://localhost:5683/basic")
|
||||
try:
|
||||
tmp = socket.gethostbyname(host)
|
||||
host = tmp
|
||||
except socket.gaierror:
|
||||
pass
|
||||
|
||||
clients = [HelperClient(server=(host, port)) for _ in range(N_client)]
|
||||
|
||||
supers = []
|
||||
for client in clients:
|
||||
client.protocol.superviseur = SuperviseurLocal(client)
|
||||
supers.append(client.protocol.superviseur)
|
||||
|
||||
def experience(client, N_rep):
|
||||
for n_rep in range(N_rep):
|
||||
response = client.get(path)
|
||||
client.stop()
|
||||
|
||||
threads = [threading.Thread(target=experience, args=[client, N_rep], name='Thread-experience-{}'.format(n)) for n, client in enumerate(clients)]
|
||||
|
||||
for thread in threads :
|
||||
thread.start()
|
||||
|
||||
for thread in threads :
|
||||
thread.join()
|
||||
|
||||
fig, axs = plt.subplots(3, sharex=True)
|
||||
for n, ax in enumerate(axs) :
|
||||
ax.hist(supers[n].RTTs, 100, density=True)
|
||||
|
||||
axs[-1].set_xlabel('RTT (s)')
|
||||
# axs[-1].set_xlim(left=0)
|
||||
|
||||
fig.tight_layout()
|
||||
fig.savefig('demo.png')
|
||||
|
||||
for super in supers:
|
||||
print(super.min_RTT, super.avg_RTT, super.tau_retransmission, super._n_tokken)
|
Loading…
Reference in a new issue