Nik-Tenzo opened a new pull request, #76304:
URL: https://github.com/apache/airflow/pull/76304

   When a task process has closed all its sockets to the supervisor but can't 
be reaped yet (it closes them before its
   interpreter finishes tearing down), `_service_subprocess` unregisters the 
last socket and the monitor loop calls it
   again with nothing left to select on. `select()` on an empty selector is a 
plain sleep, so the supervisor only sees the
   exit after up to `[workers] min_heartbeat_interval`, and on CeleryExecutor 
the worker slot stays taken meanwhile.
   
   This polls for the exit every 50 ms once nothing is left to select on, still 
bounded by the same timeout (including
   its 0.01 s floor, so a zero wait can't spin as in #50507). The select path 
is unchanged.
   
   On CeleryExecutor (Airflow 3.3.2, ECS Fargate) we saw this hold about 18% of 
slots for 30 s after their task had
   finished while we ran with `min_heartbeat_interval = 30`; at the default 5 s 
it adds up to 5 s to a task's slot time,
   which is a large share of capacity for short tasks. We've run the same 
change as a patch on our workers since.
   
   `ActivitySubprocess.wait()`, median of 3 runs, base and change alternating 
over two rounds, `min_heartbeat_interval =
   5`, macOS:
   
   | Task | Before | After |
   |---|---|---|
   | Closes its sockets, then exits 1 s later | 5.01 s | 1.02 s |
   | Control: sleeps 1 s, then exits | 1.01 s | 1.01 s |
   
   An event-driven alternative would register something that becomes readable 
when the process exits, so the existing
   `select()` wakes immediately: `os.pidfd_open(pid)` on Linux, with kqueue's 
`EVFILT_PROC` or this polling elsewhere. That
   avoids polling but needs a platform split. Happy to switch to it if that's 
preferred.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Claude Opus 5.5)
   
   Generated-by: Claude Code (Claude Opus 5.5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to