-
Notifications
You must be signed in to change notification settings - Fork 62
Adding stress test script #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dwang3851
wants to merge
6
commits into
master
Choose a base branch
from
stressTest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad2dcdf
Adding stress test script
dwang3851 aee3f6a
removing extraneous files
dwang3851 b186419
removing extraneous files
dwang3851 c4c6868
fixing linter
dwang3851 5132168
fixing coderabbit
dwang3851 6fb153d
Fixing linting issues
dwang3851 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import argparse | ||
import subprocess | ||
import time | ||
import os | ||
import sys | ||
from config import Config | ||
|
||
|
||
def run_stress_test( | ||
num_submissions, | ||
submission_delay, | ||
autograder_image, | ||
output_file, | ||
tango_port, | ||
tango_path, | ||
job_name, | ||
job_path, | ||
): | ||
with open(output_file, "a") as f: | ||
f.write(f"Stress testing with {num_submissions} submissions\n") | ||
dwang3851 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for i in range(1, num_submissions + 1): | ||
tango_cli = os.path.join(tango_path, "clients/tango-cli.py") | ||
if not os.path.isfile(tango_cli): | ||
raise ValueError(f"Tango CLI not found at: {tango_cli}") | ||
if not os.path.exists(job_path): | ||
raise ValueError(f"Job path does not exist: {job_path}") | ||
if not isinstance(tango_port, int) or not (1024 <= tango_port <= 65535): | ||
raise ValueError("Invalid port number") | ||
command = [ | ||
"python3", | ||
tango_cli, | ||
"-P", | ||
str(tango_port), | ||
"-k", | ||
"test", | ||
"-l", | ||
job_name, | ||
"--runJob", | ||
job_path, | ||
"--image", | ||
autograder_image, | ||
] | ||
try: | ||
subprocess.run(command, stdout=f, stderr=f) | ||
f.write(f"Submission {i} submitted \n") | ||
except subprocess.CalledProcessError as e: | ||
f.write(f"Error running submission {i}: {e}\n") | ||
continue | ||
if submission_delay > 0: | ||
time.sleep(submission_delay) | ||
|
||
dwang3851 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sys.exit(0) | ||
|
||
|
||
def get_metrics(output_file): | ||
if Config.LOGFILE is None: | ||
print("Make sure logs are recorded in a log file") | ||
dwang3851 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sys.exit(0) | ||
|
||
job_times = [] | ||
with open(Config.LOGFILE, "r") as f: | ||
for line in f: | ||
if "finished after " in line: | ||
start = line.find("finished after ") + len("finished after ") | ||
seconds = int(line[start:].split()[0]) | ||
job_times.append(seconds) | ||
dwang3851 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with open(output_file, "a") as f: | ||
if len(job_times) == 0: | ||
print("No jobs have been completed") | ||
else: | ||
avg = sum(job_times) / len(job_times) | ||
f.write(f"Total jobs completed: {len(job_times)} \n") | ||
f.write(f"Average job time: {avg} seconds \n") | ||
|
||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Stress test script for Tango") | ||
parser.add_argument( | ||
"--num_submissions", type=int, default=10, help="Number of submissions" | ||
) | ||
parser.add_argument( | ||
"--submission_delay", type=float, default=1.0, help="Delay between submissions" | ||
) | ||
parser.add_argument( | ||
"--autograder_image", type=str, required=True, help="Autograder image" | ||
) | ||
parser.add_argument( | ||
"--output_file", type=str, default="stress_test.out", help="Output file" | ||
) | ||
parser.add_argument( | ||
"--tango_port", type=int, default=4567, help="Tango server port" | ||
) | ||
parser.add_argument("--tango_path", type=str, required=True, help="Path to Tango") | ||
parser.add_argument("--job_name", type=str, required=True, help="Name of the job") | ||
parser.add_argument("--job_path", type=str, required=True, help="Path to the job") | ||
parser.add_argument( | ||
"--get_metrics", | ||
type=bool, | ||
default=False, | ||
help="Set to true to get metrics, does not create new jobs", | ||
) | ||
dwang3851 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
args = parser.parse_args() | ||
|
||
if args.get_metrics: | ||
get_metrics(args.output_file) | ||
else: | ||
run_stress_test( | ||
args.num_submissions, | ||
args.submission_delay, | ||
args.autograder_image, | ||
args.output_file, | ||
args.tango_port, | ||
args.tango_path, | ||
args.job_name, | ||
args.job_path, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.