Mercurial > code > home > repos > light9
annotate bin/collector_loadtest.py @ 2072:d5f1cc9615af
collector: rewrites for asyncio
author | drewp@bigasterisk.com |
---|---|
date | Sun, 22 May 2022 03:03:43 -0700 |
parents | 2951a690f1ba |
children | 2c48e92ad5d3 |
rev | line source |
---|---|
2070
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
1 #!bin/python |
2072 | 2 import asyncio |
2070
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
3 import logging |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
4 import time |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
5 from typing import cast |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
6 |
2072 | 7 from light9.collector.collector_client_asyncio import sendToCollector |
2070
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
8 from light9.effect.settings import DeviceSettings |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
9 from light9.namespaces import DEV, L9 |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
10 from light9.run_local import log |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
11 |
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
drewp@bigasterisk.com
parents:
diff
changeset
|
12 log.setLevel(logging.DEBUG) |
1858 | 13 |
14 | |
2072 | 15 async def loadTest(): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
16 print("scheduling loadtest") |
2072 | 17 n = 200000 |
18 period=1 | |
19 times = [] | |
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
drewp@bigasterisk.com
parents:
diff
changeset
|
20 session = "loadtest%s" % time.time() |
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
drewp@bigasterisk.com
parents:
diff
changeset
|
21 for i in range(n): |
2072 | 22 if i % 100 == 0: |
23 log.info('sendToCollector %s', i) | |
24 start = time.time() | |
25 await sendToCollector( | |
26 "http://localhost:8202/", | |
27 session, | |
28 DeviceSettings( | |
29 graph=None, | |
30 settingsList=[ | |
31 [DEV["backlight1"], L9["color"], "#ffffff"], # | |
32 [DEV["backlight2"], L9["color"], "#ffffff"], | |
33 [DEV["backlight3"], L9["color"], "#ffffff"], | |
34 [DEV["backlight4"], L9["color"], "#ffffff"], | |
35 [DEV["backlight5"], L9["color"], "#ffffff"], | |
36 [DEV["down2"], L9["color"], "#ffffff"], | |
37 [DEV["down3"], L9["color"], "#ffffff"], | |
38 [DEV["down4"], L9["color"], "#ffffff"], | |
39 [DEV["houseSide"], L9["level"], .8], | |
40 [DEV["backlight5"], L9["uv"], 0.011] | |
41 ])) | |
42 times.append(time.time() - start) | |
43 await asyncio.sleep(period) | |
1858 | 44 |
2072 | 45 print("loadtest done") |
46 with open('/tmp/times', 'w') as f: | |
47 f.write(''.join('%s\n' % t for t in times)) | |
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
drewp@bigasterisk.com
parents:
diff
changeset
|
48 |
1858 | 49 |
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
drewp@bigasterisk.com
parents:
diff
changeset
|
50 if __name__ == '__main__': |
2072 | 51 asyncio.run(loadTest()) |