Ejemplo n.º 1
0
 def proxy_init(self):
     self.proxy = ServiceProxy(self.loop, self.adder_path)
     connected = False
     while not connected:
         try:
             self.proxy.connect().result()
             connected = True
         except:
             time.sleep(0.1)
Ejemplo n.º 2
0
def main():
    path = "adder_service"
    name = "adder"

    loop = pyev.default_loop()

    sigwatcher = pyev.Signal(
        signal.SIGINT, loop,
        lambda watcher, events: watcher.loop.stop(pyev.EVBREAK_ALL))
    sigwatcher.start()

    service = spawn(Adder, loop, name, path)
    sproxy = ServiceProxy(loop, path)

    sproxy.connect()

    clients = []
    proxies = []

    # to push the server further (to see how fast it will really go...)
    # just add more clients!
    for x in range(30):
        bpath = "adder_bench_%i" % x
        client = spawn(AdderBench, loop, bpath, bpath, path)
        bproxy = ServiceProxy(loop, "adder_bench_1")
        bproxy.connect()
        clients.append(client)
        proxies.append(bproxy)

    loop.start()
Ejemplo n.º 3
0
 def proxy_init(self):
     self.proxy = ServiceProxy(self.loop, self.adder_path)
     connected = False
     while not connected:
         try:
             self.proxy.connect().result()
             connected = True
         except:
             time.sleep(0.1)
Ejemplo n.º 4
0
def main():
    path = "adder_service"
    name = "adder"

    loop = pyev.default_loop()

    sigwatcher = pyev.Signal(signal.SIGINT, loop, lambda watcher, events: watcher.loop.stop(pyev.EVBREAK_ALL))
    sigwatcher.start()

    service = spawn(Adder, loop, name, path)
    sproxy = ServiceProxy(loop, path)

    sproxy.connect()

    clients = []
    proxies = []

    # to push the server further (to see how fast it will really go...)
    # just add more clients!
    for x in range(30):
        bpath = "adder_bench_%i" % x
        client = spawn(AdderBench, loop, bpath, bpath, path)
        bproxy = ServiceProxy(loop, "adder_bench_1")
        bproxy.connect()
        clients.append(client)
        proxies.append(bproxy)

    loop.start()
Ejemplo n.º 5
0
class AdderBench(Service):
    def __init__(self, loop, name, path, adder_path):
        Service.__init__(self, loop, name, path)
        self.adder_path = adder_path

    def stats_init(self):
        self.add_calls = 0
        self.last_stats = time.time()
        self.stats_timer = pyev.Timer(2.0, 2.0, self.loop, self.stats)
        self.stats_timer.start()

    def stats(self, watcher, events):
        self.bench_notify(20000)
        diff = time.time() - self.last_stats
        #self.logger.info("{} calls in {} seconds, {} calls per second".format(
        #            self.add_calls, diff, self.add_calls/diff))
        self.add_calls = 0
        self.last_stats = time.time()

    def proxy_init(self):
        self.proxy = ServiceProxy(self.loop, self.adder_path)
        connected = False
        while not connected:
            try:
                self.proxy.connect().result()
                connected = True
            except:
                time.sleep(0.1)

    def run(self):
        self.signal_init()
        self.listen_init()
        self.stats_init()
        self.proxy_init()
        self.logger.info("starting")
        self.loop.start()

    @remote
    def bench_notify(self, calls):
        #self.logger.info("notify")
        start = time.time()
        for x in range(calls):
            self.proxy.notify('add', 1, 1)
        self.proxy.call('add', 1, 1)
        end = time.time()
Ejemplo n.º 6
0
class AdderBench(Service):
    def __init__(self, loop, name, path, adder_path):
        Service.__init__(self, loop, name, path)
        self.adder_path = adder_path

    def stats_init(self):
        self.add_calls = 0
        self.last_stats = time.time()
        self.stats_timer = pyev.Timer(2.0, 2.0, self.loop, self.stats)
        self.stats_timer.start()

    def stats(self, watcher, events):
        self.bench_notify(20000)
        diff = time.time() - self.last_stats
        #self.logger.info("{} calls in {} seconds, {} calls per second".format(
        #            self.add_calls, diff, self.add_calls/diff))
        self.add_calls = 0
        self.last_stats = time.time()

    def proxy_init(self):
        self.proxy = ServiceProxy(self.loop, self.adder_path)
        connected = False
        while not connected:
            try:
                self.proxy.connect().result()
                connected = True
            except:
                time.sleep(0.1)

    def run(self):
        self.signal_init()
        self.listen_init()
        self.stats_init()
        self.proxy_init()
        self.logger.info("starting")
        self.loop.start()

    @remote
    def bench_notify(self, calls):
        #self.logger.info("notify")
        start = time.time()
        for x in range(calls):
            self.proxy.notify('add', 1, 1)
        self.proxy.call('add', 1, 1)
        end = time.time()