Years ago , There is a production project . You need to send queries to multiple data tables when each customer application arrives , And in 1 The analysis results will be given in minutes . Just started using synchronization , In the case of a small amount of data, it also took dozens of seconds to read . After using asynchrony, the time is shortened , Almost ignored .
I don't think I will use asynchronous reading in the future mysql 了 , I didn't expect to review the familiar formula over the years .
I have written some before Asynchronous network request The article .
in general , The two methods are quite similar .asyncio + aiohttp
or asyncio + aiomysql
. The development mode is bottom-up :
In essence, it is the rational use of resources . If CPU Or bandwidth , Any bottleneck has reached , Then asynchronous will not be faster ( Probably a little slower , Because there are expenses ).
adopt aio The way of asynchrony can be called IO asynchronous .
Because there are delays in information exchange on the network , The synchronization method always waits until one thing is finished before doing the next , So if there is A lot of fragmentation
Task request for , that CPU Waiting ( Free ) The state of is very long .
Asynchronous mode is to synchronously initiate multiple task requests , There is no need for blocking