Finished CSV memes
This commit is contained in:
parent
4f735008ba
commit
daf2288dc6
@ -9,6 +9,8 @@ from blist import blist
|
||||
from dataclasses import dataclass
|
||||
import threading
|
||||
import queue
|
||||
import sys
|
||||
import csv
|
||||
|
||||
|
||||
@dataclass(frozen=False, init=True)
|
||||
@ -125,6 +127,20 @@ def run_benchmark(num_workers: int, timeout: float, filename: str):
|
||||
return all_requests_completed
|
||||
|
||||
|
||||
def write_results(results, file_handle):
|
||||
writer = csv.writer(file_handle)
|
||||
# fire_time = Upload complete
|
||||
# latency is in ms
|
||||
writer.writerow(['id', 'fire_time', 'response_arrive_time', 'latency'])
|
||||
|
||||
for result in results.values():
|
||||
latency = int((result.alert_arrived - result.upload_started) * 1000)
|
||||
fire_time = datetime.fromtimestamp(result.upload_finished).isoformat()
|
||||
response_arrive_time = datetime.fromtimestamp(result.alert_arrived).isoformat()
|
||||
row = [result.id, fire_time, response_arrive_time, latency]
|
||||
writer.writerow(row)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Birbnetes Benchmarker 3'
|
||||
@ -141,6 +157,8 @@ def main():
|
||||
parser.add_argument('--inflight-timeout', type=int, required=False, default=30,
|
||||
help='Number of seconds to wait for MQTT messages to arrive after uploading finished (not very precise) (0 for not waiting)')
|
||||
|
||||
parser.add_argument('--output', type=str, required=True, help='name of the file to write results to (- for stdout)')
|
||||
|
||||
parser.add_argument('--mqtt-username', type=str, required=False, default="birbnetes",
|
||||
help="Username for the MQTT server")
|
||||
parser.add_argument('--mqtt-port', type=int, required=False, default=1883, help="Port for the MQTT server")
|
||||
@ -183,7 +201,7 @@ def main():
|
||||
total_successful_uploads = len([req for req in benchmark_results.values() if req.upload_status_code == 200])
|
||||
all_arrived = False
|
||||
waiting_started = time.time()
|
||||
for _ in range(int(args.inflight_timeout*1000)):
|
||||
for _ in range(int(args.inflight_timeout * 1000)):
|
||||
if alerts_arrived_queue.qsize() >= total_successful_uploads:
|
||||
all_arrived = True
|
||||
break
|
||||
@ -225,6 +243,15 @@ def main():
|
||||
print(f"Test total runtime was {total_runtime} seconds")
|
||||
print("HTTP Request/sec:", len(benchmark_results) / total_runtime)
|
||||
|
||||
if args.output == '-':
|
||||
print("Writing results to STDOUT")
|
||||
print("\n---------- CUT HERE ----------\n")
|
||||
write_results(benchmark_results, sys.stdout)
|
||||
else:
|
||||
print("Writing results to", args.output)
|
||||
with open(args.output, 'w') as f:
|
||||
write_results(benchmark_results, f)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user