Hi Yury,
very nice work. aiomas (
https://aiomas.readthedocs.io/) works very well
with it.
I only found one problem: the default event loop's create_task() accepts
the empty string '' as host name and will bind the server to all
available interfaces. With uvloop however, I get a TypeError:
File "uvloop/loop.pyx", line 1026, in create_server (uvloop/loop.c:19287)
File "uvloop/loop.pyx", line 509, in uvloop.loop.Loop._getaddrinfo (uvloop/loop.c:12059)
TypeError: host must be a str or bytes
The low-level aiomas example attached at the end of this mail takes ~22s
with the default event loop but only ~15s with uvloop, which is ~45%
faster. :-)
Cheers,
Stefan
#
# uvloop benchmark
#
import asyncio
import aiomas
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
N_CLIENTS = 100
N_MSGS = 1000
async def handle_client(channel):
"""Handle a client connection."""
try:
while True:
req = await channel.recv()
# print(req.content)
await req.reply('cya')
except ConnectionResetError:
await channel.close()
async def client():
"""Client coroutine: Send a greeting to the server and wait for a
reply."""
channel = await aiomas.channel.open_connection(('localhost', 5555))
for _ in range(N_MSGS):
rep = await channel.send('ohai')
# print(rep)
await channel.close()
server = aiomas.run(aiomas.channel.start_server(('localhost', 5555),
handle_client))
t_clients = [client() for _ in range(N_CLIENTS)]
aiomas.run(asyncio.gather(*t_clients))
server.close()
aiomas.run(server.wait_closed())