5
5
import sys
6
6
from config import Config
7
7
8
- def run_stress_test (num_submissions , submission_delay , autograder_image , output_file , tango_port , tango_path , job_name , job_path ):
9
- with open (output_file , 'a' ) as f :
8
+
9
+ def run_stress_test (
10
+ num_submissions ,
11
+ submission_delay ,
12
+ autograder_image ,
13
+ output_file ,
14
+ tango_port ,
15
+ tango_path ,
16
+ job_name ,
17
+ job_path ,
18
+ ):
19
+ with open (output_file , "a" ) as f :
10
20
f .write (f"Stress testing with { num_submissions } submissions\n " )
11
21
for i in range (1 , num_submissions + 1 ):
12
22
command = [
13
- 'python3' , os .path .join (tango_path , 'clients/tango-cli.py' ),
14
- '-P' , str (tango_port ),
15
- '-k' , 'test' ,
16
- '-l' , job_name ,
17
- '--runJob' , job_path ,
18
- '--image' , autograder_image
23
+ "python3" ,
24
+ os .path .join (tango_path , "clients/tango-cli.py" ),
25
+ "-P" ,
26
+ str (tango_port ),
27
+ "-k" ,
28
+ "test" ,
29
+ "-l" ,
30
+ job_name ,
31
+ "--runJob" ,
32
+ job_path ,
33
+ "--image" ,
34
+ autograder_image ,
19
35
]
20
- subprocess .run (command , stdout = f , stderr = f )
21
- f .write (f"Submission { i } submitted \n " )
36
+ subprocess .run (command , stdout = f , stderr = f )
37
+ f .write (f"Submission { i } submitted \n " )
22
38
23
39
if submission_delay > 0 :
24
40
time .sleep (submission_delay )
25
-
41
+
26
42
sys .exit ()
27
43
44
+
28
45
def get_metrics (output_file ):
29
46
if Config .LOGFILE == None :
30
47
print ("Make sure logs are recorded in a log file" )
31
48
32
49
job_times = []
33
- with open (Config .LOGFILE , 'r' ) as f :
50
+ with open (Config .LOGFILE , "r" ) as f :
34
51
for line in f :
35
52
if "finished after " in line :
36
53
start = line .find ("finished after " ) + len ("finished after " )
37
54
seconds = int (line [start :].split ()[0 ])
38
55
job_times .append (seconds )
39
-
40
- with open (output_file , 'a' ) as f :
56
+
57
+ with open (output_file , "a" ) as f :
41
58
if len (job_times ) == 0 :
42
59
print ("No jobs have been completed" )
43
60
else :
44
- avg = sum (job_times )/ len (job_times )
61
+ avg = sum (job_times ) / len (job_times )
45
62
f .write (f"Average job time is { avg } seconds \n " )
46
-
63
+
47
64
sys .exit ()
48
65
49
66
50
67
if __name__ == "__main__" :
51
68
parser = argparse .ArgumentParser (description = "Stress test script for Tango" )
52
- parser .add_argument ('--num_submissions' , type = int , default = 10 , help = "Number of submissions" )
53
- parser .add_argument ('--submission_delay' , type = float , default = 1.0 , help = "Delay between submissions" )
54
- parser .add_argument ('--autograder_image' , type = str , required = True , help = "Autograder image" )
55
- parser .add_argument ('--output_file' , type = str , default = 'stress_test.out' , help = "Output file" )
56
- parser .add_argument ('--tango_port' , type = int , default = 4567 , help = "Tango server port" )
57
- parser .add_argument ('--tango_path' , type = str , required = True , help = "Path to Tango" )
58
- parser .add_argument ('--job_name' , type = str , required = True , help = "Name of the job" )
59
- parser .add_argument ('--job_path' , type = str , required = True , help = "Path to the job" )
60
- parser .add_argument ('--get_metrics' , type = bool , default = False , help = "Set to true to get metrics, does not create new jobs" )
69
+ parser .add_argument (
70
+ "--num_submissions" , type = int , default = 10 , help = "Number of submissions"
71
+ )
72
+ parser .add_argument (
73
+ "--submission_delay" , type = float , default = 1.0 , help = "Delay between submissions"
74
+ )
75
+ parser .add_argument (
76
+ "--autograder_image" , type = str , required = True , help = "Autograder image"
77
+ )
78
+ parser .add_argument (
79
+ "--output_file" , type = str , default = "stress_test.out" , help = "Output file"
80
+ )
81
+ parser .add_argument (
82
+ "--tango_port" , type = int , default = 4567 , help = "Tango server port"
83
+ )
84
+ parser .add_argument ("--tango_path" , type = str , required = True , help = "Path to Tango" )
85
+ parser .add_argument ("--job_name" , type = str , required = True , help = "Name of the job" )
86
+ parser .add_argument ("--job_path" , type = str , required = True , help = "Path to the job" )
87
+ parser .add_argument (
88
+ "--get_metrics" ,
89
+ type = bool ,
90
+ default = False ,
91
+ help = "Set to true to get metrics, does not create new jobs" ,
92
+ )
61
93
62
94
args = parser .parse_args ()
63
95
@@ -72,5 +104,5 @@ def get_metrics(output_file):
72
104
args .tango_port ,
73
105
args .tango_path ,
74
106
args .job_name ,
75
- args .job_path
76
- )
107
+ args .job_path ,
108
+ )
0 commit comments