Debug Slow Spark Job logo

Debug Slow Spark Job

Organization
EmbrasureAI
debug-slow-spark-job

Diagnose slow, expensive, or regressed Apache Spark and PySpark applications by comparing runtime evidence against a healthy run. Use for long stages, stragglers, skew, shuffle, spill, garbage collection, poor parallelism, small files, slow scans, scheduler delay, executor imbalance, and unexplained compute-cost growth.

Overview

PublisherEmbrasureAI
Repositoryspark-observability-skills
Skill namedebug-slow-spark-job
Stars
54
Forks
14
Bundled files
1
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by EmbrasureAI on GitHub. Read the source before you install it.

Installation

Install the Debug Slow Spark Job AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/EmbrasureAI/spark-observability-skills/tree/main/skills/debug-slow-spark-job
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/EmbrasureAI/spark-observability-skills.git /tmp/spark-observability-skills
mkdir -p .claude/skills
cp -r /tmp/spark-observability-skills/skills/debug-slow-spark-job .claude/skills/debug-slow-spark-job
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Debug Slow Spark Job in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Debug Slow Spark Job on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Debug Slow Spark Job is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Debug a slow Spark job

Find the root cause of the slowdown or cost growth. Compare against a healthy run whenever one exists, and normalize for input size before calling anything a regression.

Get the evidence

bash
export SPARK_HISTORY_URL="https://history.example.com"
python3 scripts/spark_history_api.py slow --app-id <slow-application-id> > /tmp/spark-slow.json
python3 scripts/spark_history_api.py slow --app-id <healthy-application-id> > /tmp/spark-healthy.json

Run from this skill directory. If SPARK_HISTORY_URL is unset, find the server before asking the user: try http://localhost:18080, a running application's UI on http://localhost:4040, and the history-server or eventLog settings in the local Spark config; ask only when nothing responds. Authentication comes from SPARK_HISTORY_AUTHORIZATION, SPARK_HISTORY_COOKIE, or SPARK_HISTORY_HEADERS_JSON; never ask for credentials in chat and never disable TLS verification (--ca-file for a private CA).

Other subcommands: applications [--status completed|running] to find app IDs, sql-list --app-id <id> and sql --app-id <id> --execution-id <n> for the executed plan with per-node metrics, failure --app-id <id> for failed-stage detail; all accept --stage-limit N --task-limit N. For anything the profiles omit, call $SPARK_HISTORY_URL/api/v1 directly with the same auth headers: /applications/{app}/jobs, /stages/{stage}/{attempt}/taskSummary?quantiles=0.05,0.5,0.95, /stages/{stage}/{attempt}/taskList?sortBy=-runtime, /allexecutors, /environment, /sql/{execution}?details=true&planDescription=true.

In taskSummary, metric arrays align with quantiles [0, 0.5, 0.95, 0.99, 1.0]: the middle entry is the median, the last is the max. Read spark.master and deploy mode from environment.sparkProperties to know where driver and executor logs live. Compare stage timelines between the two runs and start where they first diverge; wall time alone mixes queue time, driver work, execution, and commit.

Likeliest causes, in order, and how to check each

  1. Skew. Max far above median for run time, input, or shuffle read in one stage:

    bash
    jq '.longestStages[] | {stage: .stage.stageId, quantiles: .taskSummary.quantiles, run: .taskSummary.executorRunTime, input: .taskSummary.inputMetrics.bytesRead, shuffleRead: .taskSummary.shuffleReadMetrics.readBytes}' /tmp/spark-slow.json

    .longestStages[].tasks names the hot partitions and hosts. Check the executed plan (sql subcommand) for AQE skew handling (skewed=true) before proposing salting.

  2. Wrong partition count. Tasks uniformly large and spilling mean too few; tens of thousands of sub-second tasks mean scheduler overhead:

    bash
    jq '{stageTasks: [.longestStages[].stage | {id: .stageId, tasks: .numTasks}], totalCores: ([.allExecutors[] | select(.isActive) | .totalCores] | add), conf: [.environment.sparkProperties[] | select(.[0] | test("shuffle.partitions|executor.cores"))]}' /tmp/spark-slow.json

    Try spark.sql.shuffle.partitions or AQE targets before inserting explicit repartitions.

  3. Excess spill. Spill without skew means operator state outgrew execution memory:

    bash
    jq '.longestStages[] | {stage: .stage.stageId, memSpill: .taskSummary.memoryBytesSpilled, diskSpill: .taskSummary.diskBytesSpilled}' /tmp/spark-slow.json

    Reduce state (narrower rows, partial aggregation) or raise partitions before raising memory.

  4. Large shuffles. Shuffle bytes dominating stage runtime:

    bash
    jq '.longestStages[].stage | {id: .stageId, shuffleRead: .shuffleReadBytes, shuffleWrite: .shuffleWriteBytes, run: .executorRunTime}' /tmp/spark-slow.json

    Map the stage to its Exchange in the executed plan and ask whether the shuffle is avoidable: broadcast, pre-aggregation, or already-partitioned data.

  5. Slow shuffle fetch. Low CPU with high fetch wait or heavy remote reads:

    bash
    jq '.longestStages[] | {stage: .stage.stageId, fetchWait: .taskSummary.shuffleReadMetrics.fetchWaitTime, remote: .taskSummary.shuffleReadMetrics.remoteBytesRead}' /tmp/spark-slow.json

    Dead entries in .allExecutors[] | select(.isActive | not) mean data was refetched or recomputed. If environment shows Celeborn or an external shuffle service, confirm from the driver log it actually served the shuffle before tuning it.

  6. GC pressure. GC a large fraction of run time:

    bash
    jq '{stages: [.longestStages[] | {id: .stage.stageId, gc: .taskSummary.jvmGcTime, run: .taskSummary.executorRunTime}], executors: [.allExecutors[] | {id, gc: .totalGCTime, dur: .totalDuration}]}' /tmp/spark-slow.json

    Check peak memory, cache use, and object-heavy code before resizing heaps.

  7. Python UDF transport. Time concentrated at Python boundaries in the plan:

    bash
    python3 scripts/spark_history_api.py sql --app-id <id> --execution-id <n> | jq '.sqlExecution.nodes[] | select(.nodeName | test("Python")) | {nodeName, metrics}'

    Prefer native expressions or vectorized UDFs over resource changes.

  8. Retry churn. Failures that succeeded on retry inflate runtime without failing the job:

    bash
    jq '{stages: [.longestStages[].stage | select(.numFailedTasks > 0) | {id: .stageId, failed: .numFailedTasks}], jobs: [.jobs[] | select(.numFailedTasks > 0) | {jobId, failed: .numFailedTasks}]}' /tmp/spark-slow.json

    Find the flaky cause (one bad host, preemption, timeouts) in the executor log or node events.

  9. Scan overhead. Long scans with little output:

    bash
    python3 scripts/spark_history_api.py sql --app-id <id> --execution-id <n> | jq '.sqlExecution.nodes[] | select(.nodeName | startswith("Scan")) | {nodeName, metrics}'

    Too many small files, missing partition or pushed filters, or slow storage.

  10. Driver and queue time. Gaps before the first task or between jobs:

    bash
    jq '[.jobs[] | {jobId, submissionTime, completionTime}] | sort_by(.submissionTime)' /tmp/spark-slow.json

    That time is planning, file listing, queueing, or provisioning: check the driver log for what it was doing, not stage tuning.

The commands above are starting points, not limits: compose your own jq, call the REST API directly, or pull logs, code, and platform state when a question needs it. Rule each candidate in or out with evidence, and when a signal is suggestive but not conclusive, go a level deeper (more task samples, the exact log lines, the executed plan) until you are confident it is or is not the cause. Do not settle for the first plausible explanation.

For a regression, end by naming what changed: code, data volume or distribution, configuration (diff the two snapshots' environment), or infrastructure. Adding memory for a skewed partition, adding executors when task count caps parallelism, and caching once-used data are common wrong answers.

Report

State the root cause and confidence, the first divergent stage, the evidence for and against, alternatives you rejected, and the most likely fix. Do not change production settings or launch expensive reruns without approval.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Debug Slow Spark Job AI skill do?

Diagnose slow, expensive, or regressed Apache Spark and PySpark applications by comparing runtime evidence against a healthy run. Use for long stages, stragglers, skew, shuffle, spill, garbage collection, poor parallelism, small files, slow scans, scheduler delay, executor imbalance, and unexplained compute-cost growth.

Why use Debug Slow Spark Job on TypingMind?

Because you install it once and use it with any model. Debug Slow Spark Job is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Debug Slow Spark Job in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/EmbrasureAI/spark-observability-skills/tree/main/skills/debug-slow-spark-job. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Debug Slow Spark Job?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Debug Slow Spark Job?

As many as you like. As long as a model supports skills, you can use Debug Slow Spark Job with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Debug Slow Spark Job AI skill free?

Yes. It is published on GitHub by EmbrasureAI under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇