Skip to content

Commit 1cfecd1

Browse files
committed
Add scripts for auto generating random jobs and tracking cluster utilization
1 parent 0d37916 commit 1cfecd1

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from random import randint, seed
2+
import sys
3+
import os
4+
import time
5+
6+
seed(42)
7+
8+
def create_job(job_index, priority, problem_size, min_replicas, max_replicas, timesteps):
9+
with open("charm-template.yaml", "r") as file:
10+
template = file.read()
11+
12+
odf = 2
13+
num_chares = odf * max_replicas
14+
num_chares = 2 ** (num_chares - 1).bit_length()
15+
chare_size = problem_size // num_chares
16+
17+
job_yaml = template.format(
18+
job_index=job_index,
19+
priority=priority,
20+
problem_size=problem_size,
21+
chare_size=chare_size,
22+
timesteps=timesteps,
23+
min_replicas=min_replicas,
24+
max_replicas=max_replicas,
25+
)
26+
27+
with open(f"jobs/charm-job-{job_index}.yaml", "w") as file:
28+
file.write(job_yaml)
29+
30+
31+
def generate_jobs():
32+
for job_index in range(10):
33+
priority = randint(1, 5)
34+
problem_size = 2 ** (randint(9, 12))
35+
min_replicas = randint(1, 3)
36+
max_replicas = randint(min_replicas+1, 8)
37+
timesteps = 100 * randint(20, 30)
38+
create_job(job_index, priority, problem_size, min_replicas, max_replicas, timesteps)
39+
40+
41+
def submit_jobs():
42+
for job_index in range(10):
43+
job_file = f"jobs/charm-job-{job_index}.yaml"
44+
print(f"Submitting {job_file}")
45+
# Here you would submit the job using your cluster's job submission command
46+
os.system(f"kubectl apply -f {job_file}")
47+
# For this example, we'll just print the command
48+
#print(f"kubectl apply -f {job_file}")
49+
time.sleep(10)
50+
51+
52+
if __name__ == "__main__":
53+
if sys.argv[1] == "generate_jobs":
54+
generate_jobs()
55+
elif sys.argv[1] == "submit":
56+
submit_jobs()
57+
else:
58+
print("Invalid argument. Use 'generate_jobs' to generate job files or 'submit' to submit them.")
59+
sys.exit(1)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import subprocess
2+
import time
3+
4+
output_file = "/home/aditya/mpi-operator/examples/v2beta1/charm/pod_utilization.log"
5+
6+
while True:
7+
result = subprocess.run(["kubectl", "get", "pods"], capture_output=True, text=True)
8+
with open(output_file, "a") as file:
9+
file.write(result.stdout)
10+
file.write("\n")
11+
file.write("LOG> %s" % time.strftime("%Y-%m-%d %H:%M:%S"))
12+
file.write("\n")
13+
time.sleep(2)

0 commit comments

Comments
 (0)