-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclients_simulation.py
96 lines (80 loc) · 2.49 KB
/
clients_simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from multiprocessing import Process
import subprocess
import os
import sys
import shutil
import random
import time
import signal
processes = []
def signal_handler(sig, frame):
try:
for proc in processes:
proc.kill()
except:
pass
sys.exit(0)
# Deletions
try:
shutil.rmtree("common")
except:
pass
for i in os.listdir("."):
if os.path.isdir(os.path.join(".", i)):
if i.endswith("mirror") or i.endswith("input"):
shutil.rmtree(i)
# Run the client numOfInitialClients times and then every timeInterval create new client:
executable = sys.argv[1]
# Run with a single delete parameter to simply delete testing folders:
if executable == "delete":
sys.exit()
numOfInitialClients = int(sys.argv[2])
timeInterval = int(sys.argv[3])
os.mkdir("common")
signal.signal(signal.SIGTSTP, signal_handler)
ID = 1
for i in range(numOfInitialClients):
inputFileName = str(ID) + "_input"
num_of_files = random.randint(10, 30)
num_of_dirs = random.randint(5, 10)
levels = random.randint(2, 4)
print("./create_infiles.sh {} {} {} {}".format(
inputFileName, num_of_files, num_of_dirs, levels))
subprocess.check_call(
[
'./create_infiles.sh', inputFileName, str(num_of_files),
str(num_of_dirs), str(levels)])
processes.append(subprocess.Popen(
[
"./" +
executable, "-n", str(ID), "-c", "./common", "-i", "./" +
inputFileName, "-m", "./" + str(ID) + "_mirror",
"-b", "100", "-l", "log_file" + str(ID)
])
)
ID += 1
if timeInterval != None and timeInterval != 0:
while True:
time.sleep(timeInterval)
inputFileName = str(ID) + "_input"
num_of_files = random.randint(10, 30)
num_of_dirs = random.randint(5, 10)
levels = random.randint(2, 4)
print("./create_infiles.sh {} {} {} {}".format(
inputFileName, num_of_files, num_of_dirs, levels))
subprocess.check_call(
[
'./create_infiles.sh', inputFileName, str(num_of_files),
str(num_of_dirs), str(levels)])
process = subprocess.Popen(
[
"./" +
executable, "-n", str(ID), "-c", "./common", "-i", "./" +
inputFileName, "-m", "./" + str(ID) + "_mirror",
"-b", "100", "-l", "log_file" + str(ID)
])
processes.append(process)
ID += 1
else:
for i in processes:
i.wait()