|
| 1 | +import subprocess |
| 2 | +import argparse |
| 3 | +import time |
| 4 | + |
| 5 | + |
| 6 | +nozzle_perf_params = [ |
| 7 | + {"hec-workers": "1", "hec-batch-size": "100"}, |
| 8 | + {"hec-workers": "2", "hec-batch-size": "100"}, |
| 9 | + {"hec-workers": "4", "hec-batch-size": "100"}, |
| 10 | + {"hec-workers": "8", "hec-batch-size": "100"}, |
| 11 | + {"hec-workers": "16", "hec-batch-size": "100"}, |
| 12 | + {"hec-workers": "32", "hec-batch-size": "100"}, |
| 13 | + {"hec-workers": "1", "hec-batch-size": "1000"}, |
| 14 | + {"hec-workers": "2", "hec-batch-size": "1000"}, |
| 15 | + {"hec-workers": "4", "hec-batch-size": "1000"}, |
| 16 | + {"hec-workers": "8", "hec-batch-size": "1000"}, |
| 17 | + {"hec-workers": "16", "hec-batch-size": "1000"}, |
| 18 | + {"hec-workers": "32", "hec-batch-size": "1000"}, |
| 19 | +] |
| 20 | + |
| 21 | +nozzle_perf_suites = [ |
| 22 | + { |
| 23 | + "message-type": "s256byte", |
| 24 | + "extra-fields": "message_type:s256byte", |
| 25 | + "cases": nozzle_perf_params, |
| 26 | + }, |
| 27 | + { |
| 28 | + "message-type": "s1kbyte", |
| 29 | + "extra-fields": "message_type:s1kbyte", |
| 30 | + "cases": nozzle_perf_params, |
| 31 | + }, |
| 32 | + { |
| 33 | + "message-type": "uns256byte", |
| 34 | + "extra-fields": "message_type:uns256byte", |
| 35 | + "cases": nozzle_perf_params, |
| 36 | + }, |
| 37 | + { |
| 38 | + "message-type": "uns1kbyte", |
| 39 | + "extra-fields": "message_type:uns1kbyte", |
| 40 | + "cases": nozzle_perf_params, |
| 41 | + }, |
| 42 | +] |
| 43 | + |
| 44 | + |
| 45 | +def run_nozzle_perf(config): |
| 46 | + for suite in nozzle_perf_suites: |
| 47 | + for case in suite["cases"]: |
| 48 | + kvs = ",".join("{}:{}".format(k, v) for k, v in case.iteritems()) |
| 49 | + extra_fields = "{},{}".format(suite["extra-fields"], kvs) |
| 50 | + cmd = [ |
| 51 | + "./splunk-firehose-nozzle", |
| 52 | + "--api-endpoint", config["api-endpoint"], |
| 53 | + "--user", config["user"], |
| 54 | + "--password", config["password"], |
| 55 | + "--splunk-host", config["splunk-host"], |
| 56 | + "--splunk-token", config["splunk-token"], |
| 57 | + "--splunk-index", config["splunk-index"], |
| 58 | + "--hec-workers", case["hec-workers"], |
| 59 | + "--hec-batch-size", case["hec-batch-size"], |
| 60 | + "--events", "ContainerMetric,CounterEvent,Error,HttpStart,HttpStartStop,HttpStop,LogMessage,ValueMetric", |
| 61 | + "--extra-fields", extra_fields, |
| 62 | + "--add-app-info", |
| 63 | + "--enable-event-tracing", |
| 64 | + "--skip-ssl-validation-cf", |
| 65 | + "--skip-ssl-validation-splunk", |
| 66 | + ] |
| 67 | + print " ".join(cmd) |
| 68 | + execute(cmd, config["duration"]) |
| 69 | + |
| 70 | + |
| 71 | +def execute(cmd, duration): |
| 72 | + has_error = False |
| 73 | + while 1: |
| 74 | + try: |
| 75 | + start = time.time() |
| 76 | + print "start {} {}".format(" ".join(cmd), start) |
| 77 | + out, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() |
| 78 | + except Exception as e: |
| 79 | + has_error = True |
| 80 | + print e |
| 81 | + else: |
| 82 | + has_error = False |
| 83 | + print "out:", out |
| 84 | + print "err:", err |
| 85 | + finally: |
| 86 | + end = time.time() |
| 87 | + last = end - start |
| 88 | + print "end {} {} duration={}".format(" ".join(cmd), end, last) |
| 89 | + |
| 90 | + # If we run too short, rerun it |
| 91 | + if last < 0.8 * duration: |
| 92 | + print "run too short, retry..." |
| 93 | + time.sleep(1) |
| 94 | + elif has_error: |
| 95 | + pass |
| 96 | + else: |
| 97 | + break |
| 98 | + |
| 99 | + |
| 100 | +def run_trafficcontroller(duration): |
| 101 | + for suite in nozzle_perf_suites: |
| 102 | + for _ in suite["cases"]: |
| 103 | + cmd = [ |
| 104 | + "./trafficcontroller", |
| 105 | + "--config", "loggregator_trafficcontroller.json", |
| 106 | + "--disableAccessControl", |
| 107 | + "--duration", str(duration), |
| 108 | + "--message-type", suite["message-type"], |
| 109 | + ] |
| 110 | + |
| 111 | + execute(cmd, duration) |
| 112 | + time.sleep(10) |
| 113 | + |
| 114 | + |
| 115 | +def main(): |
| 116 | + parser = argparse.ArgumentParser(description="Nozzle perf test driver") |
| 117 | + parser.add_argument("--run", dest="run", required=True, help="nozzle or trafficcontroller") |
| 118 | + parser.add_argument("--duration", dest="duration", type=int, required=True, help="how long to run in seconds") |
| 119 | + args = parser.parse_args() |
| 120 | + |
| 121 | + if args.run == "nozzle": |
| 122 | + config = { |
| 123 | + "api-endpoint": "http://ghost:9911", |
| 124 | + "user": "admin", |
| 125 | + "password": "admin", |
| 126 | + "splunk-host": "https://localhost:8088", |
| 127 | + "splunk-token": "1CB57F19-DC23-419A-8EDA-BA545DD3674D", |
| 128 | + "splunk-index": "main", |
| 129 | + "duration": args.duration, |
| 130 | + } |
| 131 | + run_nozzle_perf(config) |
| 132 | + else: |
| 133 | + run_trafficcontroller(args.duration) |
| 134 | + |
| 135 | + |
| 136 | +if __name__ == "__main__": |
| 137 | + main() |
0 commit comments