Esempio n. 1
0
def main():
    opts, args = parse_options()

    if ":" in opts.bind:
        address, port = opts.bind.split(":")
        port = int(port)
    else:
        address, port = opts.bind, 8000

    if args:
        x = args[0].split(":")
        if len(x) > 1:
            nodes = [(x[0], int(x[1]))]
        else:
            nodes = [(x[0], 8000)]
    else:
        nodes = []

    manager = Manager()

    debugger = Debugger()
    debugger.IgnoreEvents.extend(["Read", "Write"])
    manager += debugger

    bridge = Bridge(port, address=address, nodes=nodes)
    manager += bridge

    manager.run()
Esempio n. 2
0
    def testBridge(self):
        """Test Bridge

        Test Bridge
        """

        m1 = Manager()
        b1 = Bridge(bind=8000, nodes=[("127.0.0.1", 8001)])
        b1.IgnoreChannels.extend(["dummy"])
        foo = Foo()
        m1 += b1
        m1 += foo
        m1.start()

        m2 = Manager()
        b2 = Bridge(bind=8001, nodes=[("127.0.0.1", 8000)])
        b2.IgnoreChannels.extend(["dummy"])
        bar = Bar()
        m2 += b2
        m2 += bar
        m2.start()

        m1.push(Event(), "bar")
        m1.push(Event(), "dummy")
        wait()

        self.assertFalse(foo.flag)
        self.assertTrue(bar.flag)

        m2.push(Event(), "foo")
        m2.push(Event(), "dummy")
        wait()

        self.assertTrue(foo.flag)
        self.assertTrue(bar.flag)

        m1.stop()
        m2.stop()

        bar.unregister()
        b2.unregister()

        foo.unregister()
        b1.unregister()
Esempio n. 3
0
    def testBridge(self):
        """Test Bridge

        Test Bridge
        """

        m1 = Manager()
        b1 = Bridge(bind=8000, nodes=[("127.0.0.1", 8001)])
        b1.IgnoreChannels.extend(["dummy"])
        foo = Foo()
        m1 += b1
        m1 += foo
        m1.start()

        m2 = Manager()
        b2 = Bridge(bind=8001, nodes=[("127.0.0.1", 8000)])
        b2.IgnoreChannels.extend(["dummy"])
        bar = Bar()
        m2 += b2
        m2 += bar
        m2.start()

        m1.push(Event(), "bar")
        m1.push(Event(), "dummy")
        wait()

        self.assertFalse(foo.flag)
        self.assertTrue(bar.flag)

        m2.push(Event(), "foo")
        m2.push(Event(), "dummy")
        wait()

        self.assertTrue(foo.flag)
        self.assertTrue(bar.flag)

        m1.stop()
        m2.stop()

        bar.unregister()
        b2.unregister()

        foo.unregister()
        b1.unregister()
Esempio n. 4
0
def main():
    opts, args = parse_options()

    if opts.speed and psyco:
        psyco.full()

    manager = Manager()

    monitor = Monitor(opts)
    manager += monitor

    state = State(opts)
    manager += state

    if opts.debug:
        manager += Debugger()

    if opts.listen or args:
        nodes = []
        if args:
            for node in args:
                if ":" in node:
                    host, port = node.split(":")
                    port = int(port)
                else:
                    host = node
                    port = 8000
                nodes.append((host, port))

        if opts.bind is not None:
            if ":" in opts.bind:
                address, port = opts.bind.split(":")
                port = int(port)
            else:
                address, port = opts.bind, 8000

        bridge = Bridge(bind=(address, port), nodes=nodes)
        manager += bridge
        bridge.start()

    if opts.mode.lower() == "speed":
        if opts.verbose:
            print "Setting up Speed Test..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += SpeedTest(opts, channel=c)
        else:
            manager += SpeedTest(opts)
        monitor.sTime = time.time()
    elif opts.mode.lower() == "latency":
        if opts.verbose:
            print "Setting up Latency Test..."
        manager += LatencyTest(opts)
        monitor.sTime = time.time()
    elif opts.listen:
        if opts.verbose:
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Receiver(opts, channel=c)
        else:
            manager += Receiver(opts)
    elif args:
        if opts.verbose:
            print "Setting up Sender..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(opts, channel=c)
        else:
            manager += Sender(opts)
    else:
        if opts.verbose:
            print "Setting up Sender..."
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(channel=c)
                manager += Receiver(opts, channel=c)
        else:
            manager += Sender(opts)
            manager += Receiver(opts)
        monitor.sTime = time.time()

    if opts.profile:
        if hotshot:
            profiler = hotshot.Profile("bench.prof")
            profiler.start()

    if not opts.wait:
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager.push(Hello("hello"), "hello", c)
        else:
            manager.push(Hello("hello"), "hello")

    while not state.done:
        try:
            manager.flush()

            for i in xrange(opts.fill):
                manager.push(Foo(), "foo")

            if opts.events > 0 and monitor.events > opts.events:
                manager.send(Stop(), "stop")
            if opts.time > 0 and (time.time() - monitor.sTime) > opts.time:
                manager.send(Stop(), "stop")

        except KeyboardInterrupt:
            manager.send(Stop(), "stop")

    if opts.verbose:
        print

    eTime = time.time()

    tTime = eTime - monitor.sTime

    events = monitor.events
    speed = int(math.ceil(float(monitor.events) / tTime))

    if opts.output:
        print opts.output % (events, speed, tTime)
    else:
        print "Total Events: %d (%d/s after %0.2fs)" % (events, speed, tTime)

    if opts.profile and hotshot:
        profiler.stop()
        profiler.close()

        stats = hotshot.stats.load("bench.prof")
        stats.strip_dirs()
        stats.sort_stats("time", "calls")
        stats.print_stats(20)
Esempio n. 5
0
def main():
    opts, args = parse_options()

    if opts.speed and psyco:
        psyco.full()

    manager = Manager()

    monitor = Monitor(opts)
    manager += monitor

    state = State(opts)
    manager += state

    if opts.debug:
        manager += Debugger()

    if opts.listen or args:
        nodes = []
        if args:
            for node in args:
                if ":" in node:
                    host, port = node.split(":")
                    port = int(port)
                else:
                    host = node
                    port = 8000
                nodes.append((host, port))

        if opts.bind is not None:
            if ":" in opts.bind:
                address, port = opts.bind.split(":")
                port = int(port)
            else:
                address, port = opts.bind, 8000

        bridge = Bridge(bind=(address, port), nodes=nodes)
        manager += bridge
        bridge.start()

    if opts.mode.lower() == "speed":
        if opts.verbose:
            print "Setting up Speed Test..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += SpeedTest(opts, channel=c)
        else:
            manager += SpeedTest(opts)
        monitor.sTime = time.time()
    elif opts.mode.lower() == "latency":
        if opts.verbose:
            print "Setting up Latency Test..."
        manager += LatencyTest(opts)
        monitor.sTime = time.time()
    elif opts.listen:
        if opts.verbose:
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Receiver(opts, channel=c)
        else:
            manager += Receiver(opts)
    elif args:
        if opts.verbose:
            print "Setting up Sender..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(opts, channel=c)
        else:
            manager += Sender(opts)
    else:
        if opts.verbose:
            print "Setting up Sender..."
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(channel=c)
                manager += Receiver(opts, channel=c)
        else:
            manager += Sender(opts)
            manager += Receiver(opts)
        monitor.sTime = time.time()

    if opts.profile:
        if hotshot:
            profiler = hotshot.Profile("bench.prof")
            profiler.start()

    if not opts.wait:
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager.push(Hello("hello"), "hello", c)
        else:
            manager.push(Hello("hello"), "hello")

    while not state.done:
        try:
            manager.flush()

            for i in xrange(opts.fill):
                manager.push(Foo(), "foo")

            if opts.events > 0 and monitor.events > opts.events:
                manager.send(Stop(), "stop")
            if opts.time > 0 and (time.time() - monitor.sTime) > opts.time:
                manager.send(Stop(), "stop")

        except KeyboardInterrupt:
            manager.send(Stop(), "stop")

    if opts.verbose:
        print

    eTime = time.time()

    tTime = eTime - monitor.sTime

    events = monitor.events
    speed = int(math.ceil(float(monitor.events) / tTime))

    if opts.output:
        print opts.output % (events, speed, tTime)
    else:
        print "Total Events: %d (%d/s after %0.2fs)" % (events, speed, tTime)

    if opts.profile and hotshot:
        profiler.stop()
        profiler.close()

        stats = hotshot.stats.load("bench.prof")
        stats.strip_dirs()
        stats.sort_stats("time", "calls")
        stats.print_stats(20)