From 74d3278258b64c7678d7388a071c07866e08d40a Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 4 Aug 2020 10:53:35 -0700 Subject: [PATCH] add python test file to benchmark how many messages can be received per second --- .../python/websockets/devnull_client.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/compatibility/python/websockets/devnull_client.py diff --git a/test/compatibility/python/websockets/devnull_client.py b/test/compatibility/python/websockets/devnull_client.py new file mode 100644 index 00000000..b4325fe7 --- /dev/null +++ b/test/compatibility/python/websockets/devnull_client.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +# websocket send client + +import argparse +import asyncio +import websockets + +try: + import uvloop + uvloop.install() +except ImportError: + print('uvloop not available') + pass + +msgCount = 0 + +async def timer(): + global msgCount + + while True: + print(f'Received messages: {msgCount}') + msgCount = 0 + + await asyncio.sleep(1) + + +async def client(url): + global msgCount + + asyncio.ensure_future(timer()) + + async with websockets.connect(url) as ws: + async for message in ws: + msgCount += 1 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='websocket proxy.') + parser.add_argument('--url', help='Remote websocket url', + default='wss://echo.websocket.org') + args = parser.parse_args() + + asyncio.get_event_loop().run_until_complete(client(args.url))