Skip to main content

Spark Sentinel

PyPI Python CI License

Find performance problems in Apache Spark jobs from their event logs, and learn how to fix them. Skew, spill, small files, missed broadcast joins, row-by-row Python UDFs, idle cores and more, each traced to the stage and SQL query that caused it, with a concrete fix and a link to the Spark documentation behind it.

Spark Sentinel analysing a skewed job in the terminal

  • No code changes. It reads the event log Spark already writes (the same file the History Server uses).
  • No cluster needed. Runs on your laptop, on logs from anywhere: local runs, Databricks, EMR, Kubernetes, Spark 3.5 and 4.x.
  • Made for CI. --fail-on high turns a performance regression into a failed build.

Install

pipx install spark-sentinel        # or: pip install spark-sentinel
uvx spark-sentinel analyze ...     # or run it without installing

Python 3.11+. You don't need Spark or Java to run Sentinel, only an event log.

Quick start

  1. Turn on event logging for your Spark job:

    spark = (
        SparkSession.builder.config("spark.eventLog.enabled", "true")
        .config("spark.eventLog.dir", "file:///tmp/spark-events")
        .getOrCreate()
    )
    

    On a cluster, logs are usually already on: look where spark.eventLog.dir points and copy the log to your machine.

  2. Analyze it:

    sentinel analyze /tmp/spark-events                    # every log in the folder
    sentinel analyze /tmp/spark-events -f html -o report.html
    
  3. Small local runs finish in seconds, so their problems are small too. Use the laptop profile to see them: sentinel analyze /tmp/spark-events --profile laptop.

The HTML report is one self-contained file that works offline, in light and dark mode:

The HTML report: verdict, app index and a skew finding with evidence bars

What it finds

Rule Problem Based on (Spark docs)
SKEW001 One task takes far longer than its siblings; tells data skew from compute skew Optimizing Skew Join
SPILL001 Tasks spill to disk for lack of execution memory Memory Usage of Reduce Tasks
GC001 Tasks spend a large share of their time in garbage collection Garbage Collection Tuning
FILES001 A write produces many small files Coalesce Hints
PART001 Too many shuffle partitions for the data Coalescing Post Shuffle Partitions
PART002 Too few shuffle partitions: huge tasks Tuning Partitions
PAR001 A long stage with fewer tasks than cores Level of Parallelism
PLAN001 A Python UDF in a filter blocks pushdown into the file scan Arrow Python UDFs
PLAN002 A join without an equality key: cartesian or nested-loop join Join Strategy Hints
PLAN003 All of a query's data goes through one task (e.g. a window without partitionBy) Avoid computation on single partition
PLAN004 A sort-merge join where one side was small enough to broadcast Automatically Broadcasting Joins
PLAN005 A Python UDF runs row by row instead of in Arrow batches Arrow Python UDFs
CONF001 Settings that switch off Spark's automatic optimizations (info) Adaptive Query Execution

The rule catalog maps every section of Spark's tuning guides to the symptom Sentinel looks for, including what's planned next and what an event log can't show. sentinel rules lists the rules with their thresholds.

Every rule is tested against a gallery of deliberately bad Spark jobs, run on Spark 3.5 and 4.3: each job must trigger its rule, and a clean job must trigger none.

Use it in CI

sentinel analyze path/to/eventlogs --fail-on high -f md -o sentinel.md
Exit code Meaning
0 Analysis ran; nothing at or above --fail-on (default: never fail on findings)
1 A finding at or above --fail-on
2 Bad options or config
3 An event log couldn't be read, or a rule crashed

Settings can live in a sentinel.toml next to your code (command-line options override it):

profile = "default"          # or "laptop" for small test jobs
fail_on = "high"
format  = "md"
ignore  = ["CONF001"]

[thresholds.SKEW001]
min_time_lost_ms = 60000

Compare two runs

sentinel diff compares a baseline run (say, from main) with a new one (from a pull request) and explains what got slower:

$ sentinel diff base-run/ pr-run/ --profile laptop
SLOWER  Query 0: 1.5x slower (3.9s → 6.0s): the broadcast join became a sort-merge join, which adds
        2 shuffles (after spark.sql.autoBroadcastJoinThreshold changed from the default to -1)
        writes report/revenue
        task time 6.0s → 14.3s · shuffle 7.0 KB → 26.3 MB
        Plan (- before, + after):
          -   +- * BroadcastHashJoin Inner BuildRight
          +   +- * SortMergeJoin Inner
          ...

Settings changed
  spark.sql.autoBroadcastJoinThreshold: (default) → -1

New problems
  MED   PLAN004  Query 0: sort-merge join where one side is only 3.1 MB
  • Queries are matched by what they do, not by their IDs. Plans are normalized (expression IDs, operator numbers and paths removed), then matched by plan, then by what they read and write. Adding a query doesn't throw off the rest.
  • Noise is filtered. A change counts only if it crosses both a percentage and an absolute threshold (laptop profile: 30% and 1 s or 8 MB; default: 25% and 30 s or 256 MB).
  • A slowdown is confirmed only if something deterministic changed with it: the join strategy, a Python UDF, the number of shuffles, spill, data volume or a related setting. A slowdown with no visible cause is reported as possible noise and doesn't fail --fail-on slower. (Wall time is noisy: a cold first run of an unchanged job measured 1.7x slower.)
  • New and fixed problems: the rules run on both runs, so a pull request that introduces a problem shows up even when it isn't slower yet.
sentinel diff baseline/ new/ --fail-on slower --fail-on high -f md -o diff.md

Each side is an event log, a folder holding one run's log, or an app ID from sentinel apps. Thresholds can be changed with --threshold min_time_ms=5000 or in sentinel.toml:

[diff]
min_change_pct = 25
min_time_ms = 10000
min_bytes = 268435456

To try it, lab/diff/sales_report.py runs a small report job plus one-line "pull requests" that break it.

Check every pull request

The GitHub Action runs sentinel diff in your workflow and comments on the pull request:

on: pull_request
permissions:
  contents: read
  pull-requests: write   # to comment

jobs:
  performance:
    runs-on: ubuntu-latest
    steps:
      # ... run a small Spark job twice with event logging on:
      #     on the base branch -> $RUNNER_TEMP/events/base
      #     on the pull request -> $RUNNER_TEMP/events/pr
      - uses: r4otxrhs3/spark-sentinel@v0.2.0
        with:
          baseline: ${{ runner.temp }}/events/base
          new: ${{ runner.temp }}/events/pr
          profile: laptop
          fail-on: slower

Running both on the same runner, one after the other, keeps machine-to-machine noise out of the comparison. The comment is updated in place on every push, and the report also goes to the job summary. spark-sentinel-demo is a complete example, with a bad pull request to try.

Input Default
baseline, new (required) An event log, or a folder holding one run's log
profile from config, else default laptop for small CI jobs
fail-on slower slower, a severity (high, medium, ...) for new problems, or never
thresholds name=value lines: min_change_pct, min_time_ms, min_bytes
config A sentinel.toml
comment true Comment on the PR (the job summary always gets the report)
comment-key default Keeps several Sentinel comments apart on one PR
sentinel-version Install this version from PyPI instead of the action's own code
python python3 Python 3.11+ for Sentinel's own virtual environment

Outputs: result (pass, fail or error), confirmed-slower, slower, new-problems, report (the Markdown file) and comment. Pull requests from forks get a read-only token, so they get the job summary and the pass/fail verdict but no comment. Runs on Linux and macOS runners.

Commands

Command What it does
sentinel analyze PATH... Read logs (if given) and report problems: --format text|md|html|json, --profile, --select, --ignore, --threshold RULE.name=value, --fail-on
sentinel diff BASELINE NEW Compare two runs: queries slower or faster and why, settings changed, new and fixed problems: --format text|md|json, --fail-on slower|<severity>, --threshold name=value
sentinel ingest PATH Parse logs once into a local Parquet warehouse (.sentinel/)
sentinel sql "SELECT ..." Query the stored tables (tasks, stages, jobs, sql, executors, config, ...) with DuckDB
sentinel apps List ingested apps
sentinel rules List rules and their thresholds
sentinel inspect PATH Show how a log is stored and count its events

How it works

event log ─▶ reader ─▶ parser ─▶ Parquet tables ─▶ DuckDB SQL ─▶ rules ─▶ report
 (plain,      (streams   (tasks, stages,   (parse once,      (one SQL query    (text, md,
  zstd, gzip,  lines)     jobs, sql plans,  query many        + diagnosis       html, json)
  rolled)                 executors, ...)   times)            per rule)

Every slow task can be traced through its stage and job to the SQL query and physical plan that produced it, which is how findings name the join key, the UDF or the repartition(500) behind a problem.

Limitations

  • Reads local files. Copy logs from S3, HDFS or DBFS first.
  • Logs compressed with Spark's lz4, lzf or snappy codecs aren't supported yet (zstd, Spark's default, and gzip are).
  • Per-operator SQL metrics (rows per plan node, files read) aren't parsed yet; the rules that need them are planned.
  • Thresholds default to production-sized jobs; use --profile laptop for small runs.
  • sentinel diff compares one app with one app, from a single run each. A change inside a Python UDF's code doesn't change the plan, so a slowdown it causes shows as unconfirmed.

Contributing

New rules are welcome. CONTRIBUTING.md walks through adding one, from the gallery job that reproduces the problem to the tests that keep it free of false alarms.

License

Apache License 2.0

Metadata

Release files for spark-sentinel 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spark-sentinel 0.2.0
File Size Uploaded Provenance Actions
spark_sentinel-0.2.0.tar.gz 1.8 MB With provenance Details for spark_sentinel-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spark-sentinel 0.2.0
File Interpreter ABI Platform Actions
spark_sentinel-0.2.0-py3-none-any.whl Python 3 none any Details for spark_sentinel-0.2.0-py3-none-any.whl

Total release size: 1.9 MB

Release files / spark_sentinel-0.2.0.tar.gz

Download URL spark_sentinel-0.2.0.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
1107a23cf350762e88ecd12a29fae8ca40064cb8e3dbcc68888ee9a0fdfef745
BLAKE2b-256 checksum
How to use checksums
06970054ff872e6a944da6c23fd7d666e8c9a407a02fdbf020b195a3e76fb55b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / spark_sentinel-0.2.0-py3-none-any.whl

Download URL spark_sentinel-0.2.0-py3-none-any.whl
Size 98.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33684889f37df6ba7384f4e36354e0f3cbb64f210a794825da27d66e8db383dc
BLAKE2b-256 checksum
How to use checksums
70db58cbd9b408b8137e4ac433f87e4f79c37a248d6fcc86086e6c8d73b26eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for spark-sentinel 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spark_sentinel-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page