Answer the question
In order to leave comments, you need to log in
Is mixing asynchronous and synchronous programming bad?
And so, I recently asked a question about choosing an asynchronous ORM for MongoDB on Python 3.7, and did not find one that would suit me in terms of the number of available fields, the main ones I considered were motorengine, umongo, aiomotorengine and about five more.
Today, in another outburst of googling, I accidentally stumbled upon an article Motor vs PyMongo - Asynchronous vs Synchronous DB calls , in which the author's asynchronous motor (on which, in fact, almost all asynchronous ORMs are built) was always slower than synchronous pymongo.
In the comments, a certain Arab explained this by saying that the motor only creates the illusion of asynchrony.
There is a simple reason why Motor is slower than pymongo. Because it is NOT truly asynchronous. Let me tell you why.
For any IO application to be called asynchronous, at the heart of it, it needs to be using NON BLOCKING SOCKETS (basic OS concepts every CS Major is aware of). Motor does not. It simply throws up a new thread (tell me about the genius in that??) every time you make a call. It is super resource intensive as a result. Each thread is simply running a pymongo instance, which finally at the end of the day, is using the same old blocking IO socket :) :D (He he he, fooled you!!!)
Once the thread retrieves the result from the socket, it returns to the caller in an non-blocking fashion, wonderfully throwing up the illusion of a so called 'asynchronicity'
Answer the question
In order to leave comments, you need to log in
On the fingers, it's like this. There are countries with right-hand traffic, there are with left-hand traffic. They drive well here and there. But the idea of stirring up a country where some streets are driven on the right and others on the left is not a good idea.
Where synchronous and asynchronous code paradigms meet, there is an overhead for their docking. This usually results in asynchronous wrappers for synchronous code. By inevitability (for example, in the absence of an asynchronous driver to the database), they do so. But the idea is so-so.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question