...

Text file src/edge-infra.dev/hack/datasync/speedTest.py

Documentation: edge-infra.dev/hack/datasync

     1import yaml
     2import subprocess
     3import time
     4def update_yaml(maxJobs, churn, interval):
     5    yaml_path = "./edge-infra/config/pallets/edge/datasync/couchdb/generic/couchdb-server.yaml"
     6    with open(yaml_path, 'r') as file:
     7        data = yaml.safe_load(file)
     8    data['spec']['replicator']['maxJobs'] = maxJobs
     9    data['spec']['replicator']['maxChurn'] = churn
    10    data['spec']['replicator']['interval'] = interval
    11    with open(yaml_path, 'w') as file:
    12        yaml.dump(data, file)
    13    
    14def run_port_forward():
    15    while True:
    16        print("Running kubectl port-forward...")
    17        process = subprocess.Popen(["kubectl", "port-forward", "-n", "data-sync-couchdb", "data-sync-couchdb-0", "5984:5984"])
    18        # Wait for a few seconds to see if the command succeeds
    19        time.sleep(10)
    20        # Check if the process is still running
    21        if process.poll() is None:
    22            print("kubectl port-forward started successfully.")
    23            return
    24        else:
    25            print("kubectl port-forward hasn't started. Retrying in 10 seconds...")
    26            command = "kill -9 $(lsof -t -i:5984)"
    27            process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
    28            time.sleep(10)
    29
    30def run_cleanup_script(skip=False):
    31    if skip:
    32        return True
    33    try:
    34        subprocess.run(["./cleanup.sh"], timeout=220)  
    35    except:
    36        print("Cleanup script timed out after 2 minutes.")
    37        return False
    38    return True
    39def run_speedHelper_script(maxJobs, churn, interval, username, password, serverURL):
    40    subprocess.run(["python3", "speedHelper.py", "--maxjobs", str(maxJobs), "--churn", str(churn), "--interval", str(interval), "-u", username, "-p", password, "-s", serverURL, "-db", database])
    41if __name__ == "__main__":
    42    # Define the values
    43    intervalArr = [5000, 10000, 15000, 40000, 60000]
    44    churnArr = [50, 100, 500]
    45    maxJobsArr = [50, 80, 10000]
    46
    47    for interval in intervalArr:
    48        for churn in churnArr:
    49            for maxJobs in maxJobsArr:
    50                if churn < maxJobs:
    51                    username = ""
    52                    password = ""
    53                    serverURL = "" # "http://localhost:5984/"
    54                    database = ""
    55                    skipCleanup = False
    56                    # Run the cleanup script
    57                    if run_cleanup_script(skip=skipCleanup):
    58                        # Run the task3 script
    59                        if not(skipCleanup):
    60                            time.sleep(120)
    61                        run_port_forward()
    62                        time.sleep(10)
    63                        run_speedHelper_script(maxJobs, churn, interval, username, password, serverURL)

View as plain text