Guest User

Untitled

a guest
Jul 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import httplib
  4. import json
  5. import os
  6. import shutil
  7. import time
  8.  
  9. def purge_tsd_cache():
  10. for dir in (dir for dir in os.listdir("/tmp/tsd") if dir[0] != "."):
  11. shutil.rmtree("/tmp/tsd/" + dir)
  12.  
  13. purge_tsd_cache()
  14.  
  15. metrics = ("ad1", "ad3")
  16.  
  17. tsd = httplib.HTTPConnection("127.0.0.1:4242")
  18. tsd.connect()
  19.  
  20. def test(metric):
  21. t = int(time.time() * 1000)
  22. req = tsd.request("GET", "/q?start=2011/02/01-00:00:00&m=sum:%s&json" % metric)
  23. resp = tsd.getresponse().read()
  24. t = int(time.time() * 1000) - t
  25. resp = json.loads(resp)
  26. print ("%7d %s points, server reported latency = %dms, our client latency = %dms"
  27. % (resp["points"], metric, resp["timing"], t))
  28. return t
  29.  
  30. print "-- warm up --"
  31. for metric in metrics:
  32. test(metric)
  33.  
  34. print "-- test --"
  35. timings = dict((metric, 0) for metric in metrics)
  36. iterations = 5
  37. for metric in metrics:
  38. for i in xrange(iterations):
  39. purge_tsd_cache()
  40. timings[metric] += test(metric)
  41.  
  42. for metric in metrics:
  43. print ("Average for %s out of %d runs: %dms"
  44. % (metric, iterations, timings[metric] / iterations))
  45.  
  46. tsd.close()
Add Comment
Please, Sign In to add comment