-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POC][WIP] Async SQLAlchemy sessions in Airflow #36504
base: main
Are you sure you want to change the base?
Conversation
I expect a long time to go/test all cases . But I love it :). But yeah, if we limit it for Connections and Variables for now, that would be cool. I think one general comment here is that not everyone will be able to use those drivers that support async operations I am afraid. There might be various limitations - dependencies, some specific corporate/managed DB configuration that is not supported - so, almost-for-sure - we should have a way to a) handle sync access I think that cleanest solution we should explicitly recognise sync/async access to Connections/Variables and enable them by a configuration flag for example and have a method/way to check it from Trigger. |
I have some ideas for testing the async drivers of each database in our CI in a short execution time (I will implement them soon). For this point:
we have different options, like fallback to sync get when the |
24c7415
to
22fc19a
Compare
22fc19a
to
943404b
Compare
943404b
to
a0e0847
Compare
Airflow Metadata is the brain of Airflow; it is the central component used to store the state of all operations and enable communication between other components.
A lot of the execution time of Airflow components is wasted waiting for some input of this Metadata, which we can avoid if we query the database asynchronously. We can perform other operations during the waiting time or send more requests to Metadata.
SQLAlchemy supports since 1.4 Asynchronous I/O (asyncio) that we can use to improve all our components:
To test and validate the efficiency of async sessions before merging complicated methods from sync to async, I implemented the utils to create the async sessions and some async methods to load the variables and the connections from the database, and I tried one of the newly implemented methods with the triggerer:
test_trigger.py:
dag.py:
I triggered a manual Dag Run, which created 1000 mapped tasks and deferred them.
I had the expected result in the log (login root) without any blocking in the event loop of the Triggerer, with reasonable resource consumption.
Then I tested by replacing the trigger run method with:
I got the result in the task log, but the Triggerer log was full of:
and the Triggerer used almost all the resources of my computer.