Exemplo n.º 1
0
    def test_pymode(self):
        args = set_frontend_parser().parse_args([])

        p_args = set_preprocessor_parser().parse_args([
            '--port_in',
            str(args.port_out), '--port_out', '5531', '--socket_in',
            str(SocketType.PULL_CONNECT), '--socket_out',
            str(SocketType.PUSH_BIND), '--yaml_path', 'SentSplitPreprocessor'
        ])

        e_args = set_encoder_parser().parse_args([
            '--port_in',
            str(p_args.port_out), '--port_out',
            str(args.port_in), '--socket_in',
            str(SocketType.PULL_CONNECT), '--socket_out',
            str(SocketType.PUSH_CONNECT), '--yaml_path', 'transformer.yml',
            '--py_path', 'distilbert.py'
        ])

        with ServiceManager(EncoderService, e_args), \
             ServiceManager(PreprocessorService, p_args), \
             FrontendService(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)
            resp = stub.Call(
                list(
                    RequestGenerator.index([
                        b'hello world, good to see you.',
                        b'goodbye! wish to see you again!'
                    ], 1))[0])
            self.assertEqual(resp.request_id, 0)
Exemplo n.º 2
0
    def test_pymode(self):
        args = set_frontend_parser().parse_args([])

        p_args = set_preprocessor_parser().parse_args([
            '--port_in', str(args.port_out),
            '--port_out', '5531',
            '--socket_in', str(SocketType.PULL_CONNECT),
            '--socket_out', str(SocketType.PUSH_BIND),
            '--yaml_path', '!UnaryPreprocessor {parameters: {doc_type: 1}}'
        ])

        e_args = set_encoder_parser().parse_args([
            '--port_in', str(p_args.port_out),
            '--port_out', str(args.port_in),
            '--socket_in', str(SocketType.PULL_CONNECT),
            '--socket_out', str(SocketType.PUSH_CONNECT),
            '--yaml_path', 'flair.yml',
        ])

        with ServiceManager(EncoderService, e_args), \
             ServiceManager(PreprocessorService, p_args), \
             FrontendService(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)
            resp = stub.Call(list(RequestGenerator.index([b'hello world', b'goodbye!'], 1))[0])
            self.assertEqual(resp.request_id, '0')
Exemplo n.º 3
0
    def _test_grpc_multiple_pub(self, backend='thread', num_parallel=5):
        args = set_frontend_parser().parse_args([
            '--grpc_host',
            '127.0.0.1',
        ])

        p_args = set_router_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), '--yaml_path', 'BaseRouter',
            '--num_parallel',
            str(num_parallel), '--parallel_backend', backend,
            '--parallel_type',
            str(ParallelType.PUB_BLOCK)
        ])

        with ServiceManager(
                RouterService,
                p_args), FrontendService(args), grpc.insecure_channel(
                    '%s:%d' % (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)
            resp = stub.Call(list(RequestGenerator.query(b'abc', 1))[0])
            self.assertEqual(resp.request_id, 0)
Exemplo n.º 4
0
    def test_grpc_frontend(self):
        args = set_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), '--yaml_path', 'BaseRouter'
        ])

        with RouterService(p_args), FrontendService(
                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
Exemplo n.º 5
0
    def test_frontend_alone(self):
        args = set_frontend_parser().parse_args([
            '--grpc_host',
            '127.0.0.1',
        ])

        with FrontendService(args):
            pass

        with ServiceManager(FrontendService, args):
            pass
Exemplo n.º 6
0
    def test_bm_frontend(self):
        args = set_frontend_parser().parse_args([
            '--grpc_host', '127.0.0.1',

        ])

        p_args = set_router_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),
            '--yaml_path', 'BaseRouter'
        ])
Exemplo n.º 7
0
    def test_cli(self):
        args = set_frontend_parser().parse_args([])

        p_args = set_router_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), '--yaml_path', 'BaseRouter'
        ])

        with RouterService(p_args), FrontendService(args):
            CLIClient(self.train_args)
            CLIClient(self.index_args)
            CLIClient(self.query_args)
Exemplo n.º 8
0
    def test_pymode(self):
        os.unsetenv('http_proxy')
        os.unsetenv('https_proxy')
        args = set_frontend_parser().parse_args([])

        p_args = set_preprocessor_parser().parse_args([
            '--port_in',
            str(args.port_out), '--port_out', '5531', '--socket_in',
            str(SocketType.PULL_CONNECT), '--socket_out',
            str(SocketType.PUSH_BIND), '--yaml_path', 'SentSplitPreprocessor'
        ])

        e_args = set_indexer_parser().parse_args([
            '--port_in',
            str(p_args.port_out),
            '--port_out',
            str(args.port_in),
            '--socket_in',
            str(SocketType.PULL_CONNECT),
            '--socket_out',
            str(SocketType.PUSH_CONNECT),
            '--yaml_path',
            '!DictIndexer {gnes_config: {name: dummy_dict_indexer}}',
        ])

        with ServiceManager(IndexerService, e_args), \
             ServiceManager(PreprocessorService, p_args), \
             FrontendService(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)
            all_bytes = []
            with open(os.path.join(self.dirname, '26-doc-chinese.txt'),
                      'r',
                      encoding='utf8') as fp:
                for v in fp:
                    if v.strip():
                        all_bytes.append(v.encode())
            for r in stub.StreamCall(RequestGenerator.index(all_bytes)):
                print(r)

        bi = BaseIndexer.load('dummy_dict_indexer.bin')
        self.assertEqual(bi.size, 26)
        print(bi.query([0]))
Exemplo n.º 9
0
    def test_bm_frontend(self):
        args = set_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), '--yaml_path', 'BaseRouter'
        ])

        b_args = set_benchmark_client_parser().parse_args(
            ['--num_requests', '10', '--request_length', '65536'])
        with RouterService(p_args), FrontendService(args):
            BenchmarkClient(b_args)
Exemplo n.º 10
0
    def test_async_block(self):
        args = set_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), '--yaml_path', 'BaseRouter'
        ])

        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), '--yaml_path', 'BaseRouter'
        ])

        with FrontendService(args), Router1(p1_args), Router2(
                p2_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
Exemplo n.º 11
0
    def test_cli(self):
        cli_args = set_client_cli_parser().parse_args([
            '--mode', 'train', '--grpc_host', '127.0.0.1', '--txt_file',
            os.path.join(self.dirname, 'sonnets.txt')
        ])

        args = set_frontend_parser().parse_args([])

        p_args = set_router_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), '--host_in', '127.0.0.1',
            '--host_out', '127.0.0.1', '--yaml_path', 'BaseRouter'
        ])

        with RouterService(p_args), FrontendService(args) as s:
            CLIClient(cli_args)
Exemplo n.º 12
0
    def setUp(self):
        os.unsetenv('http_proxy')
        os.unsetenv('https_proxy')
        self.dirname = os.path.dirname(__file__)

        self.s_args = set_grpc_service_parser().parse_args([
            '--grpc_port', '5678',
            '--grpc_host', '127.0.0.1',
            '--pb2_path', os.path.join(self.dirname, 'proto', 'dummy_pb2.py'),
            '--pb2_grpc_path', os.path.join(self.dirname, 'proto', 'dummy_pb2_grpc.py'),
            '--stub_name', 'DummyGRPCServiceStub',
            '--api_name', 'dummyAPI'
        ])

        self.args = set_frontend_parser().parse_args([
            '--grpc_host', '127.0.0.1',
            '--grpc_port', '9999',
            '--port_in', str(self.s_args.port_out),
            '--port_out', str(self.s_args.port_in),

        ])
Exemplo n.º 13
0
 def test_service_parser(self):
     args1 = set_frontend_parser().parse_args([])
     args2 = set_frontend_parser().parse_args([])
     self.assertNotEqual(args1.port_in, args2.port_in)
     self.assertNotEqual(args1.port_out, args2.port_out)