jischeng opened a new issue, #60322:
URL: https://github.com/apache/spark/issues/60322
### Describe the bug / improvement
`HybridRowQueue` buffers pass-through rows on the JVM while `EvalPythonExec`
/ `EvalPythonUDTFExec` feeds input batches to a Python worker and waits for
responses. Currently, it has two structural issues under memory pressure or
fast-producer / slow-worker workloads:
1. **Unbounded single-file disk spill without recovery**: Once
`createNewQueue` falls back to `DiskRowQueue` (for instance on a transient
`SparkOutOfMemoryError`), `DiskRowQueue.add(row)` always returns `true`. As a
result, `writing` remains pinned to that single `DiskRowQueue` for the
remainder of the task:
- Its output stream stays open and the underlying spill file grows
unboundedly rather than rotating into page-sized segments that can be closed
and deleted as the consumer drains them;
- `HybridQueue` never calls `createNewQueue` again, so it can never
recover back to `InMemoryRowQueue` pages even after queued pages are drained
and execution memory becomes available again.
2. **No optional per-queue execution memory cap**: When a fast JVM scan
feeds wide pass-through rows into a slower Python UDF/UDTF worker, a single
`HybridRowQueue` can acquire execution memory pages until the executor's
`ExecutionMemoryPool` is exhausted before spilling, starving co-running tasks
or Arrow/columnar allocators.
### Proposed Solution
1. Add `Queue.finishWrite()` (implemented on `DiskRowQueue` to close `out`
eagerly) and rotate active disk spill queues in `HybridQueue` once
`currentDiskQueueBytes >= maxDiskQueueBytes` (`pageSizeBytes` by default),
allowing drained spill files to be deleted incrementally and enabling automatic
recovery back to in-memory pages once execution memory is available.
2. Add an optional internal SQL configuration
`spark.sql.execution.python.udf.rowQueue.maxMemoryBytes` (default `-1`,
unlimited, preserving existing default behavior; `0` forces disk-only queuing;
positive values cap per-queue in-memory bytes before spilling to rolling disk
segments) and wire it into `HybridRowQueue` and
`InProcessArrowEvalPythonEvaluatorFactory`.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]