diff options
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py')
-rw-r--r-- | testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py new file mode 100644 index 0000000000..22ee4c5bd7 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/deployment/kubernetes/benchmark.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +import asyncio +import sys +import websockets + + +URI = "ws://localhost:32080" + + +async def run(client_id, messages): + async with websockets.connect(URI) as websocket: + for message_id in range(messages): + await websocket.send(f"{client_id}:{message_id}") + await websocket.recv() + + +async def benchmark(clients, messages): + await asyncio.wait([ + asyncio.create_task(run(client_id, messages)) + for client_id in range(clients) + ]) + + +if __name__ == "__main__": + clients, messages = int(sys.argv[1]), int(sys.argv[2]) + asyncio.run(benchmark(clients, messages)) |