← Back to Pull requests

Pre-split large GZIP Parquet write batches to bound GPU scratch memory #17303

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 04, 2026 09:48 UTC
Author

Contributes to #17272.

Description

Table.writeParquetChunked with CompressionType.GZIP passes all Parquet pages across all row groups of the input table into a single nvcomp::batched_compress call in libcudf, allocating temporary device scratch memory up to ~15x–19x the input table size (tracked in NVIDIA/cudf#25680). On 16 GiB GPUs (such as T4) with default spark.rapids.sql.batchSizeBytes=1g, writing wide ~1 GiB GZIP Parquet batches consistently triggers GpuSplitAndRetryOOM, host spilling, and write slowdowns even with a single active GPU task.

This PR adds a plugin-side mitigation that pre-splits oversized GZIP Parquet write batches into smaller spillable slices before calling tableWriter.write, with no new user-facing configuration and no changes to non-GZIP codecs:

  • Expose GpuDeviceManager.getPoolSizeLimit (private[rapids]).

  • Add protected def maxWriteBatchBytes: Option[Long] = None to ColumnarOutputWriter and split incoming SpillableColumnarBatches exceeding that cap (while numRows > 1) via contiguousSplit before encoding. Slices are prepended back onto pending in original row order so oversized slices from skewed variable-width rows are split again until each multi-row slice fits the cap (stopping at 1 row). Pre-splitting runs under withRetry(..., splitSpillableInHalfByRows) when retry is enabled, is timed under nvtxId / gpuTime, and preserves single-invocation statsTrackers.newBatch, semaphore release before FS I/O, and leak-free cleanup on failure.

  • Protect Cuda.DEFAULT_STREAM.sync() in SpillableColumnarBatch.apply(ContiguousTable, ...) with closeOnExcept(ct) so a stream failure cannot leak the contiguous table during ownership transfer.

  • Set maxWriteBatchBytes in GpuParquetWriter (covering Spark Parquet, Delta Lake, and Iceberg) and GpuHiveParquetWriter for CompressionType.GZIP to math.max(poolSize / 64, 64 MiB) when poolSize > 0 (~210–224 MiB slices on 16 GiB GPUs, leaving 80 GiB GPUs unsplit for default 1 GiB batches). Note that when spark.rapids.sql.format.parquet.writer.rowGroupSizeBytes is configured larger than this cap on smaller GPUs, each chunked tableWriter.write call flushes row groups bounded by the slice size.

  • Add unit tests in GpuFileFormatDataWriterSuite verifying GpuParquetFileFormat.maxWriteBatchBytesForPool, pre-splitting and exact row order/content preservation, single newBatch invocation, 1-row batches, GpuSplitAndRetryOOM during both pre-splitting and slice encoding, skewed variable-width string re-splitting (including single oversized rows), and zero-leak cleanup on unhandled failure.
  • Validation


  • Built sql-plugin, aggregator, dist, and integration_tests with Spark 3.5.2 / Scala 2.12 (mvn -Dbuildver=352 install -pl sql-plugin,aggregator,dist,integration_tests -DskipTests -Dmaven.scaladoc.skip=true): succeeded (including Apache RAT).

  • Ran isolated and full Scala GPU unit tests (GpuFileFormatDataWriterSuite): 52/52 passed, 0 failed, 0 RMM leaks (including isolated runs of both new pre-split tests).

  • Ran PySpark GZIP Parquet/Hive write integration tests on RTX 5880 Ada (TEST_PARALLEL=1 ./integration_tests/run_pyspark_from_build.sh -k '(parquet_write or hive_parquet_write or hive_write) and gzip'): 4/4 passed (test_write_gzip_parquet_into_hive_table, test_optimized_hive_ctas_gzip, test_compress_write_round_trip[gzip], test_parquet_write_gzip_save_as_table).

  • Ran full-module scalastyle (antrun:run@scalastyle-all-modules): 0 errors, 0 warnings across 2,154 files.

  • Ran python3 scripts/check_with_resource_nesting.py: passed (0 baselined violations).

  • Ran python3 build/check_shim_compatibility.py coverage: PASS (0 findings across 34 buildvers).

  • Not run locally: Scala 2.13 / Spark 4.x builds and tests, Delta/Iceberg integration tests, and Databricks runtimes.
  • Performance


    Measured on the latest head on RTX 5880 Ada with Spark 3.5.2 (local[1], 13.4 GiB RMM ARENA pool simulating a 16 GiB GPU via allocFraction=0.29, maxAllocFraction=0.29, default spark.rapids.sql.batchSizeBytes=1g, 59-column synthetic table matching the reproducer in #17272):

    | Workload | Before (main) | After (this PR) |
    |---|---|---|
    | Single ~1.0 GiB batch (1.25M rows, gzip) | 0.98s, 1 split-retry, 7.86 GB footprint (14.77 GB uncapped) | 1.02s, 0 retries, 0.0 MiB spill, 3.69 GB footprint |
    | Multi-batch ~3.0 GiB (3.75M rows, gzip) | 5.88s, 4 split-retries, 1,350.3 MiB spill, 12.99 GB footprint | 2.06s (2.85x faster), 0 retries, 0.0 MiB spill, 5.88 GB footprint |
    | Single ~1.0 GiB batch (snappy / zstd control) | 2.76 GB / 4.52 GB | 2.76 GB / 4.52 GB (unchanged) |

    Readback row counts of GZIP output matched expected counts identically (1,250,000 and 3,750,000).

    AI assistance was used to investigate the issue, implement the changes and tests, and prepare this description.

    Checklists

    Documentation

  • Updated for new or modified user-facing features or behaviors

  • No user-facing change
  • Testing

  • Added or modified tests to cover new code paths

  • Covered by existing tests

  • (Please provide the names of the existing tests in the PR description.)
  • Not required
  • Performance

  • Tests ran and results are added in the PR description

  • Issue filed with a link in the PR description

  • Not required
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: thirtiseven Review duration: 1118m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #17303"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%