testing max connections and performance websockets

This commit is contained in:
Askill 2022-04-23 15:51:11 +02:00
commit efc65e2fdc
3 changed files with 40 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
**/venv/*

25
clients.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python
import asyncio
import time
import websockets
async def hello(x, string):
async with websockets.connect("ws://localhost:8765") as websocket:
for _ in range(100):
await websocket.send(string)
await websocket.recv()
async def main(x):
string = "Did you ever hear the tragedy of Darth Plagueis The Wise? I thought not. Its not a story the Jedi would tell you. Its a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life… He had such a knowledge of the dark side that he could even keep the ones he cared about from dying. The dark side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful… the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. Ironic. He could save others from death, but not himself."
string2 = "Hi"
coros = [hello(i, string) for i in range(x)]
await asyncio.gather(*coros)
if __name__ == '__main__':
for i in range(100, 12000, 1000):
t1 = time.time()
loop = asyncio.get_event_loop()
loop.run_until_complete(main(i))
used = time.time() - t1
print(i, used/i)

14
server.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env python
import asyncio
import websockets
async def echo(websocket):
async for message in websocket:
await websocket.send(message)
async def main():
async with websockets.serve(echo, "localhost", 8765):
await asyncio.Future() # run forever
asyncio.run(main())