The JIRA issue is optional, but if there is already one that is relevant link to it here. Using the Jira issue macro is preferred.
|
For long-running tasks (e.g. jobs on cloud providers), operators and sensors often poll for task status and/or task outputs to determine the success or failure of a task. These task monitoring processes are often blocking operations that can incur various problems, including:
blocking wait operations that needlessly occupy a worker
limited concurrency on local executor
wasted resources on distributed executors
db-sync operations for rescheduling
passing XCom task-ID data
To enable the use of various non-blocking async options for hooks, sensors and operators, an async ecosystem is required and especially an async event loop (executor), task scheduler, and associated asyncio libraries for db-connections etc. Along with that, various ways to enhance existing blocking code with async options is required.
One possibility to explore is to first add an option for an AsyncExecutor that can be used like the LocalExecutor. The goal of an initial POC is to enable a Sensor and/or an Operator to use async methods for blocking operations. For example, when a blocking process is polling for status information from a remote service (cloud operator), the process might invoke a `time.sleep` call between polling periods. For this AIP to work, any of those `time.sleep` calls should have an option to be replaced with an `asyncio.sleep` call; maybe something like:
async def delay(pause, use_async=None):
if use_async is None:
use_async = os.environ.get('AIRFLOW_USE_ASYNC', False)
if use_async:
await asyncio.sleep(pause)
else:
# blocking function in async function, probably better design patterns than this
time.sleep(pause) |
See also:
This AIP is different than the following, but they share similar goals for optimize concurrency and performance.
Related work on operators that can be stateful and reschedule job status pokes (like sensor-rescheduling)
Related work specifically invoking an event loop (asyncio):
Tangential work
Is there anything special to consider about this AIP? Downsides? Difficulty in implementation or rollout etc?
For higher concurrency in some areas of interaction with cloud providers, e.g. AWS services, using asyncio patterns might improve performance, esp. for blocking operations like polling for task status on external systems.
Consider options for async event loops, in addition to the asyncio module, e.g.
Consider options for async-db drivers, e.g.
Async options to watch the DAG-BAG