[Python-ideas] An alternate approach to async IO
Sturla Molden
sturla at molden.no
Wed Nov 28 01:47:26 CET 2012
Den 28. nov. 2012 kl. 01:15 skrev Trent Nelson <trent at snakebite.org>:
>
> Right, that's why I proposed using non-Python types as buffers
> whilst in the background IO threads. Once the thread finishes
> processing the event, it pushes the necessary details onto a
> global interlocked list. ("Details" being event type and possibly
> a data buffer if the event was 'data received'.)
>
> Then, when aio.events() is called, CPython code (holding the GIL)
> does an interlocked/atomic flush/pop_all, creates the relevant
> Python objects for the events, and returns them in a list for
> the calling code to iterate over.
>
> The rationale for all of this is that this approach should scale
> better when heavily loaded (i.e. tens of thousands of connections
> and/or Gb/s traffic). When you're dealing with that sort of load
> on a many-core machine (let's say 16+ cores), an interlocked list
> is going to reduce latency versus 16+ threads constantly vying for
> the GIL.
>
>
Sure, the GIL is a lot more expensive than a simple mutex (or an interlocked list), so avoiding a GIL-release and reacquire on each io completion event might be an advantage.
Sturla
More information about the Python-ideas
mailing list