annotate bin/collector_loadtest.py @ 2293:c070f46c0761

you can ask to apply empty patch and it will no-op
author drewp@bigasterisk.com
date Tue, 30 May 2023 00:59:20 -0700
parents 2c48e92ad5d3
children
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
2078
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
4 import random
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
5 from rdflib import URIRef
2070
2951a690f1ba collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents: 1866
diff changeset
6 import time
2951a690f1ba collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents: 1866
diff changeset
7
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
8 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
9 from light9.effect.settings import DeviceSettings
2951a690f1ba collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents: 1866
diff changeset
10 from light9.namespaces import DEV, L9
2951a690f1ba collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents: 1866
diff changeset
11 from light9.run_local import log
2951a690f1ba collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents: 1866
diff changeset
12
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
13 log.setLevel(logging.DEBUG)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
14
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
15
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
16 async def loadTest():
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
17 print("scheduling loadtest")
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
18 n = 200000
2078
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
19 period=.02
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
20 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
21 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
22 for i in range(n):
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
23 if i % 100 == 0:
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
24 log.info('sendToCollector %s', i)
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
25 start = time.time()
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
26 await sendToCollector(
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
27 "http://localhost:8202/",
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
28 session,
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
29 DeviceSettings(
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
30 graph=None,
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
31 settingsList=[
2078
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
32 # [DEV["backlight1"], L9["color"], "#ffffff"], #
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
33 # [DEV["backlight2"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
34 # [DEV["backlight3"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
35 # [DEV["backlight4"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
36 # [DEV["backlight5"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
37 # [DEV["down2"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
38 # [DEV["down3"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
39 # [DEV["down4"], L9["color"], "#ffffff"],
2c48e92ad5d3 make loadtest real enough to cause numbers to change on collector's web view
drewp@bigasterisk.com
parents: 2072
diff changeset
40 [URIRef('http://light9.bigasterisk.com/theater/skyline/device/down1'), L9["brightness"], random.random()],
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
41 [DEV["backlight5"], L9["uv"], 0.011]
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
42 ]))
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
43 times.append(time.time() - start)
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
44 await asyncio.sleep(period)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
45
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
46 print("loadtest done")
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
47 with open('/tmp/times', 'w') as f:
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
48 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
49
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1830
diff changeset
50
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
51 if __name__ == '__main__':
2072
d5f1cc9615af collector: rewrites for asyncio
drewp@bigasterisk.com
parents: 2070
diff changeset
52 asyncio.run(loadTest())