// Muhammad Rasyad Caesarardhi & Gemini 3.8 Flash

Solving Streaming Queue Starvation in Fabric with Programmatic JVM Fair Scheduling

Data EngineeringApache SparkMicrosoft FabricStructured StreamingPerformance

When you consolidate a multi-table Change Data Capture (CDC) pipeline—say, 12 transactional tables streaming into Delta Lake from one database—into a single Spark Structured Streaming job, you immediately run into the noisy neighbor problem.

In our 12-table stress test running at 127 transactions per second, a single workflow history table accounted for 80.3% of all incoming volume (270,198 out of 336,423 records in a 1-hour sustained run). Meanwhile, 11 smaller operational and credit tables shared the exact same Spark driver and executor pools.

Under Spark’s default FIFO scheduler, whenever that “elephant” table triggered a heavy Delta MERGE, every lightweight table queued behind it—pushing overall sub-minute (<=60s) SLA compliance down to 5.9% and sending p99 end-to-end latency past 10 minutes.

Here is why standard Spark Fair Scheduler XML configuration crashes on Microsoft Fabric, and how programmatic JVM pool injection lifted our 1-hour SLA compliance to 96.25%.

The Trap: Why fairscheduler.xml Throws OneLake ABFS 400 Errors

The textbook Spark solution is straightforward: enable FAIR scheduling and point Spark to an XML allocation file:

spark.conf.set("spark.scheduler.mode", "FAIR")
spark.conf.set("spark.scheduler.allocation.file", "/tmp/fairscheduler.xml")

When we deployed that configuration to Microsoft Fabric, the Spark driver immediately failed with:

Spark_System_OLC_BadRequestOperationFailed: OneLake ABFS HTTP 400 Bad Request

Why It Crashes

  1. Unqualified Path Interception: On Fabric Spark, fs.defaultFS points to your workspace’s OneLake Lakehouse endpoint (abfss://...). Unqualified filesystem paths are intercepted and resolved against OneLake rather than the local container /tmp disk.
  2. Strict /Files or /Tables Prefix: OneLake rejects any ABFS path that doesn’t sit cleanly inside /Files or /Tables—so /tmp/fairscheduler.xml triggers an instant HTTP 400 Bad Request.
  3. Spark File vs. Hadoop Path Mismatch: Inside Spark’s FairSchedulableBuilder, XML loading checks local java.io.File semantics in ways that clash with remote abfss:// URIs.

The Fix: Direct JVM TaskScheduler Pool Injection via Py4J

Instead of fighting filesystem resolution with XML files, we bypass disk I/O altogether. While Spark still needs spark.scheduler.mode = FAIR configured at session creation, we register the individual scheduling pools programmatically in memory right after SparkSession initializes by calling into Spark’s TaskSchedulerImpl.rootPool() over Py4J:

from pyspark.sql import SparkSession


def configure_fair_scheduler_pools(spark: SparkSession) -> None:
    """Register tiered Fair Scheduler pools directly on the JVM TaskScheduler rootPool."""
    jvm = spark.sparkContext._jvm
    root_pool = spark.sparkContext._jsc.sc().taskScheduler().rootPool()
    scheduling_mode_cls = jvm.org.apache.spark.scheduler.SchedulingMode
    pool_cls = jvm.org.apache.spark.scheduler.Pool

    tiers = [
        # Tier 1: Elephant workflow table (~80.3% of traffic)
        ("pool_wf_task_list", scheduling_mode_cls.FAIR(), 2, 4),
        # Tier 2: Medium-volume tables (3% - 4% each)
        ("pool_daily_aging", scheduling_mode_cls.FIFO(), 1, 2),
        ("pool_decision_engine", scheduling_mode_cls.FIFO(), 1, 2),
        ("pool_credit_review", scheduling_mode_cls.FIFO(), 1, 2),
        # Tier 3: Lightweight operational tables (0.5% - 1.5% each)
        ("pool_lightweight_default", scheduling_mode_cls.FIFO(), 0, 1),
    ]

    for pool_name, mode, min_share, weight in tiers:
        if root_pool.getSchedulableByName(pool_name) is None:
            pool = pool_cls(pool_name, mode, min_share, weight)
            root_pool.addSchedulable(pool)

Then inside each streaming query’s foreachBatch function, simply bind the thread’s local property to its designated pool before calling DeltaTable.merge(...):

spark.sparkContext.setLocalProperty("spark.scheduler.pool", assigned_pool)
flowchart LR B["12 Concurrent CDC Streams"] -->| Thread-Local Pool | RT["TaskSchedulerImpl.rootPool() (In-Memory Py4J)"] RT -->| Weight 4 / MinShare 2 | T1["Tier 1: Elephant Table (80.3% Volume)"] RT -->| Weight 2 / MinShare 1 | T2["Tier 2: Medium Tables (3x Streams)"] RT -->| Weight 1 / MinShare 0 | T3["Tier 3: Light Tables (Anti-Starvation)"]

Why Tiered Weights Beat Equal Pools

  • Guaranteed Slots for Heavy Load (minShare = 2, weight = 4): The elephant stream never starves during multi-batch bursts.
  • Anti-Starvation for Light Streams: Lightweight tables get their own dedicated pool slots and no longer sit behind multi-hundred-thousand-row shuffles.
  • Zero Filesystem Footprint: 100% in-memory JVM registration—impossible to break with OneLake ABFS 400 path errors.

Benchmark Results: 1-Hour Sustained Stress Test (336,423 Rows @ 127 trx/s)

We measured end-to-end latency from source database commit timestamp to Silver Delta ingestion across all 12 tables:

Sub-Minute (<=60s) CDC SLA Compliance Progression

Oct 19: Unbounded Baseline5.9%
Oct 21: Default B2S Pool8.8%
Oct 21: 3-Node Scaled Environment63.9%
Oct 23: 30-Min + JVM Fair Scheduler89.59%
Oct 23: 1-Hour Sustained + JVM Fair Scheduler96.25%

In the final 1-hour sustained stress run (336,423 total records across 6 cycles at 127 trx/s):

  • Sub-Minute SLA Compliance: 96.25% (323,803 / 336,423 rows arrived in Silver in <= 60s).
  • Universal Sub-Minute P90: Every single one of the 12 tables achieved a p90 latency under 60 seconds (48.4s to 57.0s; overall p90 = 51.93s, overall p50 = 37.02s).
  • 87.4% Tail-Latency Collapse: Overall p99 latency dropped from 617.8s (~10.3 min) on Oct 21 to 78.01s.
  • Zero Starvation on the Elephant Table: Accounting for 80.3% of all rows (270,198 records), the heavy table still achieved 96.3% compliance (p50: 36.9s, p90: 51.7s).
WARNING

Watch Out for the 6.24 GB Spark EventLog HTTP 413 Trap in 24/7 Streams:
While validating continuous multi-day runs on Fabric, we discovered that Spark’s SingleEventLogFileWriter writes every microbatch task event into a single unrolled .inprogress file on ADLS Gen2. After ~15 hours of 13 concurrent streams polling every 20 seconds, that file crossed 6,238,548,327 bytes (~6.24 GB), hitting Azure Storage’s block flush limit (HTTP 413 RequestBodyTooLarge). While AsyncEventQueue error isolation kept the Delta merges running at 100% accuracy (7,620 simulated rows verified with 0 loss), History Server updates froze and driver stderr inflated by +11.48 MB/hour. Pairing continuous streaming jobs with a graceful watchdog restart (--max-runtime-seconds waiting for isTriggerActive == False) prevents unbounded .inprogress event log growth.

Key Takeaway

When running multi-table streaming ingestion inside managed cloud Spark platforms like Microsoft Fabric, don’t let a single high-volume table dictate tail latency for your entire platform—and don’t rely on local XML config files when fs.defaultFS intercepts paths to OneLake. Registering tiered FAIR/FIFO pools directly on TaskSchedulerImpl.rootPool() via Py4J gives you predictable, starvation-free SLAs with zero storage side effects.

Co-authored with Gemini 3.8 Flash.