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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2070
2951a690f1ba collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents: 1866
diff changeset
1 #!bin/python
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
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
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
13
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
14
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
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
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
17 n = 200000
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
18 period=1
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
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
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
22 if i % 100 == 0:
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
23 log.info('sendToCollector %s', i)
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
24 start = time.time()
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
25 await sendToCollector(
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
26 "http://localhost:8202/",
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
27 session,
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
28 DeviceSettings(
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
29 graph=None,
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
30 settingsList=[
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
31 [DEV["backlight1"], L9["color"], "#ffffff"], #
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
32 [DEV["backlight2"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
33 [DEV["backlight3"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
34 [DEV["backlight4"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
35 [DEV["backlight5"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
36 [DEV["down2"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
37 [DEV["down3"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
38 [DEV["down4"], L9["color"], "#ffffff"],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
39 [DEV["houseSide"], L9["level"], .8],
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
40 [DEV["backlight5"], L9["uv"], 0.011]
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
41 ]))
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
42 times.append(time.time() - start)
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
43 await asyncio.sleep(period)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
44
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
45 print("loadtest done")
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
46 with open('/tmp/times', 'w') as f:
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
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
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
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
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
51 asyncio.run(loadTest())