Skip to content

Instantly share code, notes, and snippets.

@tsuna
Created November 19, 2012 21:02
Show Gist options
  • Save tsuna/4113855 to your computer and use it in GitHub Desktop.
Save tsuna/4113855 to your computer and use it in GitHub Desktop.
Trivial script to load random data in OpenTSDB as quickly as possible.
#!/usr/bin/python
import os
import socket
import sys
import time
ITERATIONS = 4000
TAGS = 50
pid = os.getpid()
tsd = socket.socket()
tsd.connect(('127.0.0.1', 4242))
start = time.time()
def rate(iteration):
timing = time.time() - start
n = iteration * TAGS
return "%d in %f secs: %d/s" % (n, timing, n / timing)
for i in xrange(ITERATIONS):
ts = 1200000000 + i
#print "%d.." % (i * TAGS),
sys.stdout.flush()
buf = "\n".join("put test.sample %d %d tag1=aa%d tag2=bb%d"
% (ts, j, j, j)
for j in xrange(TAGS))
tsd.sendall(buf + "\n")
if i and i % 1000 == 0:
print "[%d] %s" % (pid, rate(i))
tsd.close()
print "[%d] Done: %s" % (pid, rate(ITERATIONS))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment