diff --git a/bin/collector_loadtest.py b/bin/collector_loadtest.py --- a/bin/collector_loadtest.py +++ b/bin/collector_loadtest.py @@ -1,65 +1,51 @@ #!bin/python +import asyncio import logging import time from typing import cast -import twisted.internet.reactor -from light9.collector.collector_client import sendToCollector +from light9.collector.collector_client_asyncio import sendToCollector from light9.effect.settings import DeviceSettings from light9.namespaces import DEV, L9 from light9.run_local import log -from twisted.internet.interfaces import IReactorCore -reactor = cast(IReactorCore, twisted.internet.reactor) log.setLevel(logging.DEBUG) -def loadTest(): +async def loadTest(): print("scheduling loadtest") - n = 2500 - times = [None] * n + n = 200000 + period=1 + times = [] session = "loadtest%s" % time.time() - offset = 0 for i in range(n): + if i % 100 == 0: + log.info('sendToCollector %s', i) + start = time.time() + await sendToCollector( + "http://localhost:8202/", + session, + DeviceSettings( + graph=None, + settingsList=[ + [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] + ])) + times.append(time.time() - start) + await asyncio.sleep(period) - def send(i): - if i % 100 == 0: - log.info('sendToCollector %s', i) - d = sendToCollector( - "http://localhost:8202/", - session, - DeviceSettings( - graph=None, - settingsList=[ - [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() + print("loadtest done") + with open('/tmp/times', 'w') as f: + f.write(''.join('%s\n' % t for t in times)) if __name__ == '__main__': - loadTest() + asyncio.run(loadTest())