A
A
Alexander Momot2017-04-13 17:38:03
Python
Alexander Momot, 2017-04-13 17:38:03

What is asyncio and what is the real difference from multithreading?

There used to be promises (in terms of javascript) and basically the trend was to discuss multi-threaded programming - creating threads and managing them: how to properly arrange semaphores, wait / not wait for an event, etc.
Now there is a lot of talk about coroutines and asynchronous code execution of the so-called. asyncio (in python terms). What is the main difference in multitasking operating systems of this approach, advantages and disadvantages, why was it needed at all, and how does it differ from the multithreaded approach, when your application creates several threads and they work, as it were, in parallel?
Are there real examples that use this approach?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2017-04-13
@AlexMt

One person puts a pot on the stove, waits for it to boil, throws in dumplings, waits for it to cook, removes it, puts in a second one, waits for it to boil ... - sequential single-threaded execution.
One person puts two pots on the stove, as soon as one of them boils, throws dumplings, etc. - asynchronous execution.
Two people put two pots... - multi-threaded execution.
Obviously, with asynchronous execution, fewer resources are required, and the speed is the same as with multi-threaded execution. That is why the c10k problem can only be solved by asynchronous servers. The downsides are that asynchronous code is more complex and not everything can be done asynchronously.

R
res2001, 2017-04-13
@res2001

apache is a multi-threaded web server.
nginx is asynchronous.
Guess why nginx is put on tasks serving 100500 requests per second?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question