Skip to content

Commit

Permalink
new experiment version
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardesd committed Nov 17, 2020
1 parent 2043bf4 commit ed5dcb5
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions locality_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
from datetime import datetime
from pathlib import Path

NUM_SUBSCRIBERS = 150
NUM_PUBLISHERS = math.floor(NUM_SUBSCRIBERS / 100)
NUMBER_SIMULATIONS = 5
NUM_SUBSCRIBERS = 15
NUM_PUBLISHERS = 1
NUMBER_SIMULATIONS = 1
qos_list = [0, 1, 2]
qos_list = [0]
topic_name = "topic"
message_delay = 1
CLUSTER_SIZE = 5

DELAY = 20
DELAY = 5

locality_dict = {
0: {
Expand Down Expand Up @@ -83,9 +84,8 @@ def start_tcpdump(_path):
def start_clients(_subscribers, _publisher, _qos, _path, _file_name):
random.shuffle(_subscribers)
for indx, sub in enumerate(_subscribers):
print(_file_name + str(indx))
subscriber_cmd = "docker exec -t mn.sub{id} python sub_thread.py -h 10.0.{id}.100 " \
"-t {topic} -q {qos} -m {msg} -c {clients} --folder {folder} --file-name {name} &".format(
subscriber_cmd = "docker exec -d mn.sub{id} python3 mosquitto_sub.py -h 10.0.{id}.100 " \
"-t {topic} -q {qos} -m {msg} -c {clients} --folder {folder} --file-name {name}".format(
id=sub,
topic=topic_name,
qos=_qos,
Expand All @@ -94,7 +94,7 @@ def start_clients(_subscribers, _publisher, _qos, _path, _file_name):
folder=_path,
name="{}_{}".format(_file_name, indx))

os.system(subscriber_cmd)
subprocess.Popen(subscriber_cmd, shell=True)
print("Subscriber {id} created".format(id=sub))

time.sleep(DELAY)
Expand All @@ -114,7 +114,6 @@ def start_clients(_subscribers, _publisher, _qos, _path, _file_name):

os.system(publisher_cmd)


def simulation(sim_num):
for q in qos_list:
for loc, clients in locality_dict.items():
Expand Down Expand Up @@ -152,6 +151,16 @@ def simulation(sim_num):

time.sleep(DELAY / 2)

# kill mosquitto_sub pids
for sub_id in sub_list:
ps_cmd = "docker exec -t mn.sub{} ps | grep python3 | awk '{{print $1}}'".format(sub_id)
sub_pid = subprocess.getoutput(ps_cmd)
sub_pid = [int(x) for x in sub_pid.split("\n") if x]
for pid in sub_pid:
cmd = "docker exec -t mn.sub{} kill -2 {}".format(sub_id, int(pid))
print(cmd)
subprocess.getoutput(cmd)

# kill other processes
os.killpg(os.getpgid(stats_pid.pid), signal.SIGTERM)
for pid in tcpdump_pid:
Expand Down

0 comments on commit ed5dcb5

Please sign in to comment.