Mercurial > code > home > repos > light9
diff bin/collector_loadtest.py @ 1493:4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
Ignore-this: 9f32a0cb0ba3c1b29ccbe7330ed15bf4
author | drewp@bigasterisk.com |
---|---|
date | Mon, 13 Jun 2016 20:04:11 +0000 |
parents | |
children | 8e0e5b3db301 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/collector_loadtest.py Mon Jun 13 20:04:11 2016 +0000 @@ -0,0 +1,46 @@ +import sys +sys.path.append('bin') +from run_local import log +from light9.effect.sequencer import sendToCollector, sendToCollectorZmq +from light9.namespaces import L9, DEV +from twisted.internet import reactor +import time +import logging +log.setLevel(logging.DEBUG) +def loadTest(): + print "scheduling loadtest" + n = 2500 + times = [None] * n + session = "loadtest%s" % time.time() + offset = 0 + for i in range(n): + def send(i): + if i % 100 == 0: + log.info('sendToCollector %s', i) + d = sendToCollector("http://localhost:999999/", session, + [[DEV["backlight1"], L9["color"], "#ffffff"], + [DEV["backlight2"], L9["color"], "#ffffff"], + [DEV["backlight3"], L9["color"], "#ffffff"], + [DEV["backlight4"], L9["color"], "#ffffff"], + [DEV["backlight5"], L9["color"], "#ffffff"], + [DEV["down2"], L9["color"], "#ffffff"], + [DEV["down3"], L9["color"], "#ffffff"], + [DEV["down4"], L9["color"], "#ffffff"], + [DEV["houseSide"], L9["level"], .8], + [DEV["backlight5"], L9["uv"], 0.011]]) + def ontime(dt, i=i): + times[i] = dt + d.addCallback(ontime) + reactor.callLater(offset, send, i) + offset += .002 + + def done(): + print "loadtest done" + with open('/tmp/times', 'w') as f: + f.write(''.join('%s\n' % t for t in times)) + reactor.stop() + reactor.callLater(offset+.5, done) + reactor.run() + +if __name__ == '__main__': + loadTest()