Fifty Airflow sensors waiting on files leave no free worker slots — why, and what fixes it?
In poke mode, the default, a sensor holds its worker and pool slot for the whole wait, so 50 waiting sensors starve the workers. reschedule frees the slot between checks (up_for_reschedule); a deferrable operator hands the wait to the triggerer.
- Believing a poking sensor releases its worker slot between checks
- Tuning
poke_intervalto fix starvation when the cause is the mode - Using
reschedulefor checks every few seconds, where rescheduling overhead outweighs the freed slot
- Why can a sensor in
reschedulemode not keep state in memory between checks? - When does a deferrable operator beat
reschedulemode, and what does it need running?
The mode follows from the expected wait versus the check interval. poke pays off when the file arrives within seconds and checks must be frequent: rescheduling every few seconds costs more than the held slot. For waits of minutes or hours use reschedule: between checks the task instance sits in up_for_reschedule and holds neither a worker slot nor a pool slot. When the sensor has a deferrable variant, the whole wait moves to the triggerer — one async process holds thousands of waits — but a triggerer must be running.
from airflow.providers.standard.sensors.filesystem import FileSensor
wait_for_file = FileSensor(
task_id="wait_for_file",
filepath="/data/in/{{ ds }}/orders.csv",
mode="reschedule", # slot is free between checks
poke_interval=300,
timeout=6 * 60 * 60,
)