[Tutor] async learning

Leam Hall leamhall at gmail.com
Tue Jul 4 20:34:53 EDT 2023


On 7/4/23 18:21, Mats Wichmann wrote:
> On 7/4/23 16:02, Alan Gauld via Tutor wrote:
>> On 02/07/2023 13:21, Leam Hall wrote:
>>> Until recently, I haven't had a lot of reason to do async stuff. ...> but it runs slower than the non-async version. Thoughts?
>>
>> I'm no expert but trivial tasks often run slower on async
>> architecture than when in a single process, even a single
>> thread.
>>
>> I don;t know how you measured things or what kind of tasks
>> you were doing, but if a single task takes less than a few
>> milliseconds to execute it's likely that the overheads in
>> async are higher than the benefits of concurrency.
>>
>> Try creating a task that takes some time such as opening a
>> file and processing its contents in some
>> way(search/sort/convert/calculate something per line, say). Then create
>> many such
>> files and have your code process them all. That should show
>> a gain of some sort.
> 
> This one does (fetches from a url, the classic example of a "slow" operation in computer terms), but... it's not happening in an async function.  As a first step, "add_stuff" needs to be an "async def".

Thanks! I'll give that a go. The code I posted was the minimum I could find to demonstrate what I was trying to do.

Leam

-- 
Software Engineer          (reuel.net/resume)
Scribe: The Domici War     (domiciwar.net)
General Ne'er-do-well      (github.com/LeamHall)


More information about the Tutor mailing list