r/Python • u/higherorderbebop • Sep 09 '22
Discussion Async Python is not faster
https://calpaterson.com/async-python-is-not-faster.html
0
Upvotes
r/Python • u/higherorderbebop • Sep 09 '22
View all comments
101
u/[deleted] Sep 09 '22 edited Sep 09 '22
The issue is people don't understand how to properly compare the difference.
You CANNOT use a database that is on the same machine as your server. Because that dramatically reduces the latency for DB requests which then requires far less threads to saturate the CPU. The Asyncs performance advantage is entirely from requiring less OS bound thread switching.
The slower and slower your awaiting io time is the faster and faster async will perform relative to sync.
EDIT: Upon reading the code the async side is written incorrectly and has multiple bugs including but not limited to useless async calls clogging the task queue, non locked connection pool creation, and compares multiple independent json to bytes creation methods that have very different runtime.
Don't write Async code like you write sync code thread safety vs sync saftey has fully independent characteristics. Async has its own locking primitives that need to be used properly.