Skip to content

Commit ad2dcdf

Browse files
committed
Adding stress test script
1 parent 182e322 commit ad2dcdf

File tree

8 files changed

+102
-1
lines changed

8 files changed

+102
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ pip-selfcheck.json
2727

2828
# Backup files
2929
*.bak
30+

clients/job11/autograde-Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
all:
2+
tar xvf autograde.tar
3+
(cd random; ./driver.sh)

clients/job11/autograde.tar

10 KB
Binary file not shown.

clients/job11/maxsubarray.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def maxsubarray(nums):
2+
n = len(nums)
3+
if n == 1:
4+
return nums[0]
5+
lookup = [0] * n
6+
lookup[0] = nums[0]
7+
res = nums[0]
8+
for i in range(1, n):
9+
lookup[i] = max(lookup[i-1]+nums[i], nums[i])
10+
res = max(res, lookup[i])
11+
return res

dump.rdb

9.83 KB
Binary file not shown.

pyvenv.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
home = /opt/homebrew/opt/[email protected]/bin
2+
implementation = CPython
3+
version_info = 3.10.13.final.0
4+
virtualenv = 20.25.0
5+
include-system-site-packages = false
6+
base-prefix = /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.10
7+
base-exec-prefix = /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.10
8+
base-executable = /opt/homebrew/opt/[email protected]/bin/python3.10

stressTest.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import argparse
2+
import subprocess
3+
import time
4+
import os
5+
import sys
6+
from config import Config
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:
10+
f.write(f"Stress testing with {num_submissions} submissions\n")
11+
for i in range(1, num_submissions + 1):
12+
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
19+
]
20+
subprocess.run(command, stdout = f, stderr = f)
21+
f.write(f"Submission {i} submitted \n")
22+
23+
if submission_delay > 0:
24+
time.sleep(submission_delay)
25+
26+
sys.exit()
27+
28+
def get_metrics(output_file):
29+
if Config.LOGFILE == None:
30+
print("Make sure logs are recorded in a log file")
31+
32+
job_times = []
33+
with open(Config.LOGFILE, 'r') as f:
34+
for line in f:
35+
if "finished after " in line:
36+
start = line.find("finished after ") + len("finished after ")
37+
seconds = int(line[start:].split()[0])
38+
job_times.append(seconds)
39+
40+
with open(output_file, 'a') as f:
41+
if len(job_times) == 0:
42+
print("No jobs have been completed")
43+
else:
44+
avg = sum(job_times)/len(job_times)
45+
f.write(f"Average job time is {avg} seconds \n")
46+
47+
sys.exit()
48+
49+
50+
if __name__ == "__main__":
51+
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")
61+
62+
args = parser.parse_args()
63+
64+
if args.get_metrics:
65+
get_metrics(args.output_file)
66+
else:
67+
run_stress_test(
68+
args.num_submissions,
69+
args.submission_delay,
70+
args.autograder_image,
71+
args.output_file,
72+
args.tango_port,
73+
args.tango_path,
74+
args.job_name,
75+
args.job_path
76+
)

worker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def run(self):
159159
"""run - Step a job through its execution sequence"""
160160
try:
161161
# Hash of return codes for each step
162+
start_time = time.time()
162163
ret = {}
163164
ret["waitvm"] = None
164165
ret["copyin"] = None
@@ -319,7 +320,8 @@ def run(self):
319320
# Job termination. Notice that Tango considers
320321
# things like runjob timeouts and makefile errors to be
321322
# normal termination and doesn't reschedule the job.
322-
self.log.info("Success: job %s:%d finished" % (self.job.name, self.job.id))
323+
elapsed_secs = time.time() - start_time
324+
self.log.info("Success: job %s:%d finished after %d seconds" % (self.job.name, self.job.id, elapsed_secs))
323325

324326
# Move the job from the live queue to the dead queue
325327
# with an explanatory message

0 commit comments

Comments
 (0)