Mercurial > code > home > repos > light9
annotate bin/collector_loadtest.py @ 2070:2951a690f1ba
collector takes requests from bin/collector_loadtest.py
author | drewp@bigasterisk.com |
---|---|
date | Sat, 21 May 2022 19:16:34 -0700 |
parents | 3c523c71da29 |
children | d5f1cc9615af |
rev | line source |
---|---|
2070
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
1 #!bin/python |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
2 import logging |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
3 import time |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
4 from typing import cast |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
5 |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
6 import twisted.internet.reactor |
1866
3c523c71da29
pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents:
1859
diff
changeset
|
7 from light9.collector.collector_client 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 from twisted.internet.interfaces import IReactorCore |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
12 |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
13 reactor = cast(IReactorCore, twisted.internet.reactor) |
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
|
14 log.setLevel(logging.DEBUG) |
1858 | 15 |
16 | |
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
|
17 def loadTest(): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
18 print("scheduling loadtest") |
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
|
19 n = 2500 |
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 times = [None] * n |
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 offset = 0 |
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
|
23 for i in range(n): |
1858 | 24 |
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
|
25 def send(i): |
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
|
26 if i % 100 == 0: |
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
|
27 log.info('sendToCollector %s', i) |
2070
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
28 d = sendToCollector( |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
29 "http://localhost:8202/", |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
30 session, |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
31 DeviceSettings( |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
32 graph=None, |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
33 settingsList=[ |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
34 [DEV["backlight1"], L9["color"], "#ffffff"], # |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
35 [DEV["backlight2"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
36 [DEV["backlight3"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
37 [DEV["backlight4"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
38 [DEV["backlight5"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
39 [DEV["down2"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
40 [DEV["down3"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
41 [DEV["down4"], L9["color"], "#ffffff"], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
42 [DEV["houseSide"], L9["level"], .8], |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
43 [DEV["backlight5"], L9["uv"], 0.011] |
2951a690f1ba
collector takes requests from bin/collector_loadtest.py
drewp@bigasterisk.com
parents:
1866
diff
changeset
|
44 ])) |
1858 | 45 |
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
|
46 def ontime(dt, i=i): |
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
|
47 times[i] = dt |
1858 | 48 |
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 d.addCallback(ontime) |
1858 | 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 reactor.callLater(offset, send, i) |
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
|
52 offset += .002 |
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
|
53 |
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
|
54 def done(): |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
55 print("loadtest done") |
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
|
56 with open('/tmp/times', 'w') as f: |
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
|
57 f.write(''.join('%s\n' % t for t in times)) |
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
|
58 reactor.stop() |
1858 | 59 |
60 reactor.callLater(offset + .5, done) | |
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
|
61 reactor.run() |
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
|
62 |
1858 | 63 |
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
|
64 if __name__ == '__main__': |
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
|
65 loadTest() |