tarasko / picows

Ultra-fast websocket client and server for asyncio
MIT License
116 stars 6 forks source link

async on_ws_frame hooks #6

Closed leftys closed 2 hours ago

leftys commented 2 hours ago

Hi, do you have any idea how to make reading the data asynchronous? Eg. making the on_ws_frame function async? I tried asyncio.create_task and pushing the data into asyncio.Queue, but both is pretty slow.

tarasko commented 2 hours ago

No, I have no idea.

That was the reason why I decided not to provide async iteration interface like aiohttp and websockets do. Because both create_task and Queue are slow and introduce significant delay and a lot of churn for the event loop.

Which is very undesirable when there is a spike in market activity.

Internally that's what aiohttp and websockets do. Internally they have same non-async on_ws_frame or similar, and they set result for a future object. And later event loop picks it up and wakes up user coroutine.