Changeset - 4294ed82ee16
[Not reviewed]
default
0 1 1
drewp@bigasterisk.com - 9 years ago 2016-06-13 20:04:11
drewp@bigasterisk.com
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
Ignore-this: 9f32a0cb0ba3c1b29ccbe7330ed15bf4
2 files changed with 58 insertions and 23 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
#!bin/python
 
from __future__ import division
 
from rdflib import Graph, URIRef, Literal
 
from twisted.internet import reactor
 
from twisted.internet import reactor, utils
 
from twisted.web.server import Site
 
from txzmq import ZmqEndpoint, ZmqFactory, ZmqPullConnection
 
import json
 
import logging
 
import klein
 
import optparse
 
@@ -77,34 +77,23 @@ def launch(graph, doLoadTest=False):
 
    reactor.listenTCP(networking.collector.port,
 
                      Site(server.app.resource()),
 
                      interface='::')
 
    log.info('serving http on %s, zmq on %s', networking.collector.port,
 
             networking.collectorZmq.port)
 
    if doLoadTest:
 
        loadTest()
 

	
 

	
 
def loadTest():
 
    from light9.effect.sequencer import sendToCollector
 
    import time
 
    session = "loadtest%s" % time.time()
 
    offset = 0
 
    for i in range(2000):
 
        reactor.callLater(offset, sendToCollector, "http://dash:8200/live/", session,
 
                    [["http://light9.bigasterisk.com/device/backlight1","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/backlight2","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/backlight3","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/backlight4","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/backlight5","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/down2","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/down3","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/down4","http://light9.bigasterisk.com/color","#ffffff"],
 
                     ["http://light9.bigasterisk.com/device/backlight5","http://light9.bigasterisk.com/uv",0.011]])
 
        offset += .005
 

	
 
    reactor.callLater(offset, reactor.stop)
 
        # in a subprocess since we don't want this client to be
 
        # cooperating with the main event loop and only sending
 
        # requests when there's free time
 
        def afterWarmup():
 
            log.info('running collector_loadtest')
 
            d = utils.getProcessValue('bin/python', ['bin/collector_loadtest.py'])
 
            def done(*a):
 
                log.info('loadtest done')
 
                reactor.stop()
 
            d.addCallback(done)
 
        reactor.callLater(2, afterWarmup)
 
    
 
def main():
 
    parser = optparse.OptionParser()
 
    parser.add_option("-v", "--verbose", action="store_true",
 
                      help="logging.DEBUG")
 
    parser.add_option("--loadtest", action="store_true",
bin/collector_loadtest.py
Show inline comments
 
new file 100644
 
import sys
 
sys.path.append('bin')
 
from run_local import log
 
from light9.effect.sequencer import sendToCollector, sendToCollectorZmq
 
from light9.namespaces import L9, DEV
 
from twisted.internet import reactor
 
import time
 
import logging
 
log.setLevel(logging.DEBUG)
 
def loadTest():
 
    print "scheduling loadtest"
 
    n = 2500
 
    times = [None] * n
 
    session = "loadtest%s" % time.time()
 
    offset = 0
 
    for i in range(n):
 
        def send(i):
 
            if i % 100 == 0:
 
                log.info('sendToCollector %s', i)
 
            d = sendToCollector("http://localhost:999999/", session,
 
                    [[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()
 

	
 
if __name__ == '__main__':
 
    loadTest()
0 comments (0 inline, 0 general)