Example #1
0
async def worker(port, num_concurrent_streams, num_requests_per_stream,
                 num_rounds, message_size, load_type):
    async with purerpc.insecure_channel("localhost", port) as channel:
        stub = GreeterStub(channel)
        if load_type == "unary":
            load_fn = do_load_unary
        elif load_type == "stream":
            load_fn = do_load_stream
        else:
            raise ValueError(f"Unknown load type: {load_type}")
        for idx in range(num_rounds):
            start = time.time()
            task_results = anyio.create_queue(sys.maxsize)
            async with anyio.create_task_group() as task_group:
                for _ in range(num_concurrent_streams):
                    await task_group.spawn(load_fn, task_results, stub, num_requests_per_stream, message_size)
            end = time.time()

            rps = num_concurrent_streams * num_requests_per_stream / (end - start)

            latencies = []
            for _ in range(num_concurrent_streams):
                latencies.append(await task_results.get())

            print("Round", idx, "rps", rps, "avg latency", 1000 * sum(latencies) / len(latencies))
Example #2
0
async def worker(port, queue, num_concurrent_streams, num_requests_per_stream,
                 num_rounds, message_size, load_type):
    async with purerpc.insecure_channel("localhost", port) as channel:
        stub = GreeterStub(channel)
        if load_type == "unary":
            load_fn = do_load_unary
        elif load_type == "stream":
            load_fn = do_load_stream
        else:
            raise ValueError(f"Unknown load type: {load_type}")
        for _ in range(num_rounds):
            start = time.time()
            task_results = anyio.create_queue(sys.maxsize)
            async with anyio.create_task_group() as task_group:
                for _ in range(num_concurrent_streams):
                    await task_group.spawn(load_fn, task_results, stub,
                                           num_requests_per_stream,
                                           message_size)
            end = time.time()
            rps = num_concurrent_streams * num_requests_per_stream / (end -
                                                                      start)
            queue.put(rps)
            results = []
            for _ in range(num_concurrent_streams):
                results.append(await task_results.get())
            queue.put(results)
        queue.close()
        queue.join_thread()
Example #3
0
async def main_coro():
    # await curio.spawn(print_memory_growth_statistics(), daemon=True)
    async with purerpc.insecure_channel("localhost", 50055) as channel:
        for i in range(100):
            start = time.time()
            async with curio.TaskGroup() as task_group:
                for i in range(100):
                    await task_group.spawn(worker(channel))
            print("RPS: {}".format(10000 / (time.time() - start)))
Example #4
0
async def main():
    async with purerpc.insecure_channel("localhost", 50051) as channel:
        stub = ChallengeStub(channel)

        challenge = await stub.create(ChallengeRequest(name='Mr. Easy'))
        print(challenge.id, challenge.name)

        async def challenge_requests(name):
            for i in range(2):
                yield ChallengeRequest(name=f'({i} {name}')

        async for challenge in stub.bulk_create(
                challenge_requests('Mr. Bulk Easy')):
            print(challenge.id, challenge.name)

        async for challenge in stub.list(Empty()):
            print(challenge.id, challenge.name)
Example #5
0
 async def new_corofunc(*, port_fixture_value, **kwargs):
     import purerpc
     async with purerpc.insecure_channel("127.0.0.1",
                                         port_fixture_value) as channel:
         await corofunc(**kwargs, channel=channel)