malinjawi commented on PR #13595: URL: https://github.com/apache/gluten/pull/13595#issuecomment-7022334517
> 1. **Velox off-heap allocations** generating native columnar batches. > 2. **In-flight Arrow batches** buffered in the queue (`QueueCapacity = 4`). > 3. **Lance's native Rust encoder buffers**, which (as noted in the description) are unmanaged by Spark's `TaskMemoryManager`. > > Could we: > > 1. **Validate peak native memory consumption** under concurrent large-vector writes and clarify how Lance's encoder memory is bounded or released under memory pressure? > 2. **Make the writer queue capacity configurable**: Expose `QueueCapacity` in `VeloxLanceConfig` (e.g., `spark.gluten.sql.columnar.backend.velox.lance.writerQueueCapacity`, defaulting to `4`) so that memory-constrained environments or high-concurrency executors can tune queue depth. > 3. **Provide memory sizing guidance**: Add a note in `VeloxLance.md` advising users to sufficiently size `spark.executor.memoryOverhead` / `spark.executor.memoryOverheadFactor` when enabling native Lance writes for high-volume or vector-heavy workloads. Thanks for the detailed review @rajarajangs Going through it in your order. **The three layers** 1. Velox batches: counted. They come from Velox memory pools, which Gluten counts against spark.memory.offHeap.size. 2. The queue: counted. Queued items are still Velox batches, and everything the writer allocates on the Arrow side goes through the task's Arrow allocator, which reports to Spark too. The queue holds at most 4 batches, each capped by spark.gluten.sql.columnar.maxBatchSize. If that budget runs out, the task fails with a Spark OOM rather than the container getting killed. 3. Lance's encoder: not counted, same as with lance-spark's own writer. In Lance 12 (what lance-spark 0.9.0-beta.2 uses) it buffers up to 8 MiB per column before writing a page ([source](https://github.com/lance-format/lance/blob/v12.0.0/rust/lance-file/src/writer/structural.rs#L406-L410)), and it copies what it buffers instead of holding on to our batches. So its size depends on the number of columns, not on how much data the task writes. **Your asks** 1. Validate peak memory. I measured how much the process footprint grew during the write (sampled every 50 ms), next to Spark's counted off-heap peak in brackets. Spark 3.5, 2.3 GiB of float vectors per write, median of 3 runs: | | 8 writers, 1536-dim | 8 writers, 3072-dim | 14 writers, 1536-dim | |---|---|---|---| | Reading only, no write | 2.16 (1.06) GiB | 2.18 (1.06) GiB | 3.62 (1.59) GiB | | Native write | 2.66 (1.62) GiB | 2.67 (1.63) GiB | 4.22 (2.86) GiB | | lance-spark's writer | 3.43 (1.19) GiB | 3.90 (1.19) GiB | 5.77 (2.08) GiB | Native adds 0.5 to 0.6 GiB over just reading, and Spark's count goes up by at least as much. `lance-spark` writer, which is what runs when native is off, uses 0.8 to 1.5 GiB more than native, and Spark barely counts it. With 3x more data per task the native write still added the same ~0.5 GiB, so it doesn't grow with the size of the write. On memory pressure: Lance doesn't react to Spark's, so Spark can't make it shrink. That's why the docs note below matters. 2. Configurable queue. I tried capacities 1, 4 and 16. Going from 4 to 1 saves only ~30 MiB per writer, and 16 used no more than 4. Since it's small, already counted, and shrinks with maxBatchSize, I kept it a constant and added a comment saying why. If a real workload needs it, it's easy to add later. 3. Sizing guidance. Added to the Limitations in VeloxLance.md: leave room in `spark.executor.memoryOverhead` for Lance's encoder, which buffers up to 8 MiB per column for each file it writes, so it grows with the number of columns and concurrent write tasks per executor. One caveat: this ran in local mode, which is like one executor with that many cores, writing to local disk. S3 adds Lance's upload buffers, but that's the same Lance code for both writers. Happy to run it on a cluster workload if you have one in mind. -- 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]
