Created
February 27, 2011 09:29
-
-
Save tsuna/846049 to your computer and use it in GitHub Desktop.
Quick script to run a couple queries against a TSD and time it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import httplib | |
import json | |
import os | |
import shutil | |
import time | |
def purge_tsd_cache(): | |
for dir in (dir for dir in os.listdir("/tmp/tsd") if dir[0] != "."): | |
shutil.rmtree("/tmp/tsd/" + dir) | |
purge_tsd_cache() | |
metrics = ("ad1", "ad3") | |
tsd = httplib.HTTPConnection("127.0.0.1:4242") | |
tsd.connect() | |
def test(metric): | |
t = int(time.time() * 1000) | |
req = tsd.request("GET", "/q?start=2011/02/01-00:00:00&m=sum:%s&json" % metric) | |
resp = tsd.getresponse().read() | |
t = int(time.time() * 1000) - t | |
resp = json.loads(resp) | |
print ("%7d %s points, server reported latency = %dms, our client latency = %dms" | |
% (resp["points"], metric, resp["timing"], t)) | |
return t | |
print "-- warm up --" | |
for metric in metrics: | |
test(metric) | |
print "-- test --" | |
timings = dict((metric, 0) for metric in metrics) | |
iterations = 5 | |
for metric in metrics: | |
for i in xrange(iterations): | |
purge_tsd_cache() | |
timings[metric] += test(metric) | |
for metric in metrics: | |
print ("Average for %s out of %d runs: %dms" | |
% (metric, iterations, timings[metric] / iterations)) | |
tsd.close() |
Author
tsuna
commented
Feb 27, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment