Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
Add Comment
Please, Sign In to add comment