示例#1
0
    def test_async_block(self):
        args = set_grpc_frontend_parser().parse_args([
            '--grpc_host',
            '127.0.0.1',
        ])

        p1_args = set_router_service_parser().parse_args([
            '--port_in',
            str(args.port_out),
            '--port_out',
            '8899',
            '--socket_in',
            str(SocketType.PULL_CONNECT),
            '--socket_out',
            str(SocketType.PUSH_CONNECT),
        ])

        p2_args = set_router_service_parser().parse_args([
            '--port_in',
            str(p1_args.port_out),
            '--port_out',
            str(args.port_in),
            '--socket_in',
            str(SocketType.PULL_BIND),
            '--socket_out',
            str(SocketType.PUSH_CONNECT),
        ])

        with Router1(p1_args), Router2(p2_args), GRPCFrontend(
                args), grpc.insecure_channel(
                    '%s:%s' % (args.grpc_host, args.grpc_port),
                    options=[
                        ('grpc.max_send_message_length', 70 * 1024 * 1024),
                        ('grpc.max_receive_message_length', 70 * 1024 * 1024)
                    ]) as channel:
            stub = gnes_pb2_grpc.GnesRPCStub(channel)
            id = 0
            with TimeContext('non-blocking call'
                             ):  # about 26s = 32s (total) - 3*2s (overlap)
                resp = stub.StreamCall(
                    RequestGenerator.train(self.all_bytes2, 1))
                for r in resp:
                    self.assertEqual(r.request_id, str(id))
                    id += 1

            id = 0
            with TimeContext('blocking call'):  # should be 32 s
                for r in RequestGenerator.train(self.all_bytes2, 1):
                    resp = stub.Call(r)
                    self.assertEqual(resp.request_id, str(id))
                    id += 1
示例#2
0
    def test_benchmark4(self):
        all_msgs = self.build_msgs2()

        with ZmqClient(self.c1_args) as c1, ZmqClient(self.c2_args) as c2:
            with TimeContext('send->recv, squeeze_pb=False'):
                for m in all_msgs:
                    c1.send_message(m, squeeze_pb=False)
                    c2.recv_message()

        with ZmqClient(self.c1_args) as c1, ZmqClient(self.c2_args) as c2:
            with TimeContext('send->recv, squeeze_pb=True'):
                for m in all_msgs:
                    c1.send_message(m, squeeze_pb=True)
                    c2.recv_message()
    def test_bench_numpy_list(self):
        for cls in [
                ListKeyIndexer, NumpyKeyIndexer, ListNumpyKeyIndexer,
                DictKeyIndexer
        ]:
            a = cls()
            b_size = 1000
            with TimeContext('%s:add()' % cls.__name__):
                for k, w in zip(batch_iterator(self.key_offset, b_size),
                                batch_iterator(self.weights, b_size)):
                    a.add(k, w)

            with TimeContext('%s:query()' % cls.__name__):
                for k in batch_iterator(self.query, b_size):
                    a.query(k)
示例#4
0
    def test_grpc_frontend(self):
        args = set_grpc_frontend_parser().parse_args([
            '--grpc_host',
            '127.0.0.1',
        ])

        p_args = set_router_service_parser().parse_args([
            '--port_in',
            str(args.port_out),
            '--port_out',
            str(args.port_in),
            '--socket_in',
            str(SocketType.PULL_CONNECT),
            '--socket_out',
            str(SocketType.PUSH_CONNECT),
        ])

        with RouterService(p_args), GRPCFrontend(args), grpc.insecure_channel(
                '%s:%s' % (args.grpc_host, args.grpc_port),
                options=[('grpc.max_send_message_length', 70 * 1024 * 1024),
                         ('grpc.max_receive_message_length', 70 * 1024 * 1024)
                         ]) as channel:
            stub = gnes_pb2_grpc.GnesRPCStub(channel)
            with TimeContext('sync call'):  # about 5s
                resp = list(
                    stub.StreamCall(RequestGenerator.train(self.all_bytes,
                                                           1)))[-1]

            self.assertEqual(resp.request_id, str(len(
                self.all_bytes)))  # idx start with 0, but +1 for final FLUSH
示例#5
0
    def test_benchmark5(self):
        all_msgs = self.build_msgs2()
        all_msgs_bak = copy.deepcopy(all_msgs)

        with ZmqClient(self.c1_args) as c1, ZmqClient(self.c2_args) as c2:
            with TimeContext('send->recv, squeeze_pb=True'):
                for m, m1 in zip(all_msgs, all_msgs_bak):
                    c1.send_message(m, squeeze_pb=True)
                    r_m = c2.recv_message()

                    for d, r_d in zip(m1.request.index.docs, r_m.request.index.docs):
                        for c, r_c in zip(d.chunks, r_d.chunks):
                            np.allclose(blob2array(c.embedding), blob2array(r_c.embedding))
                            np.allclose(blob2array(c.blob), blob2array(r_c.blob))