Skip to content

Instantly share code, notes, and snippets.

@ereyes01
Last active February 24, 2016 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ereyes01/28d671a7fdafd8932bf7 to your computer and use it in GitHub Desktop.
Save ereyes01/28d671a7fdafd8932bf7 to your computer and use it in GitHub Desktop.
A script that helps you benchmark your firebase performance
#!/usr/bin/env python
import json
import sys
import subprocess
count = int(sys.argv[1])
url = sys.argv[2]
curl = "curl -so /dev/null -w '" + '{"http_code": %{http_code}, "time_total": %{time_total}, "time_namelookup": %{time_namelookup}, "time_connect": %{time_connect}, "time_appconnect": %{time_appconnect}, "time_pretransfer": %{time_pretransfer}, "time_redirect": %{time_redirect}, "time_starttransfer": %{time_starttransfer}, "size_download": %{size_download}, "size_upload": %{size_upload}, "size_header": %{size_header}, "size_request": %{size_request}, "speed_download": %{speed_download}, "speed_upload": %{speed_upload} }' + "' "
failures = 0
non2xx = 0
num5xx = 0
num4xx = 0
collect = [
"time_total",
"time_namelookup",
"time_connect",
"time_appconnect",
"time_pretransfer",
"time_redirect",
"time_starttransfer",
"speed_download",
"speed_upload",
]
avg_stats = {}
max_stats = {}
for field in collect:
avg_stats[field] = 0.0
max_stats[field] = 0.0
left = count
while left > 0:
left -= 1
try:
out = subprocess.check_output(curl + url, shell=True)
except subprocess.CalledProcessError:
failures += 1
sys.stderr.write("!")
continue
sample = json.loads(out)
http_code = sample["http_code"]
if http_code < 200 or http_code > 299:
non2xx += 1
sys.stderr.write("X")
if http_code >= 500 and http_code <= 599:
num5xx += 1
elif http_code >= 400 and http_code <= 499:
num4xx += 1
else:
sys.stderr.write(".")
for field in collect:
avg_stats[field] += sample[field]
if sample[field] > max_stats[field]:
max_stats[field] = sample[field]
print("\nTries: {}".format(count))
print("Curl failures: {}".format(failures))
print("Non-2xx Codes: {}".format(non2xx))
print("Num 4xx Codes: {}".format(num4xx))
print("Num 5xx Codes: {}".format(num5xx))
for field in collect:
print("Avg {}: {}".format(field, avg_stats[field] / (count - failures)))
print("Max {}: {}".format(field, max_stats[field]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment