Jump to content

Spark plugin

From Open Lakehouse Wiki
Revision as of 00:52, 25 November 2026 by Open Lakehouse Wiki sync (talk | contribs) (Sync from open-lakehouse/wiki@7c9abaa)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Spark plugin
Also known as SparkPlugin, driver plugin, executor plugin
Field Extension APIs
Key parts SparkPlugin, DriverPlugin, ExecutorPlugin, PluginContext (metrics, configuration, driver RPC), spark.plugins
Open source implementations Apache Spark (since 3.0.0)
Related Spark listener, Executor, Native execution engine (Spark), Apache Gluten, DataFusion Comet
Last verified 23 November 2026 against the v4.3.0 tag of apache/spark (SparkPlugin.java, DriverPlugin.java, ExecutorPlugin.java, PluginContext.java, config/package.scala, docs/monitoring.md), Spark JIRA SPARK-29397, the Apache Gluten v1.7.0 README, the Apache DataFusion Comet 1.2.0 README and source, and the spark-rapids v26.10.0 configuration docs.

A Spark plugin is a class implementing org.apache.spark.api.plugin.SparkPlugin that Apache Spark loads into an application at startup, running one component inside the driver and one inside every executor. Plugins can initialize resources before tasks run, publish custom metrics through Spark's metrics system, react to task start and end on executors, and send messages from executors to the driver. The API was added in Spark 3.0.0 and is marked as a developer API.[1][2]

How do you load a Spark plugin?

Plugins are loaded by listing their class names in spark.plugins (since 3.0.0). A second setting, spark.plugins.defaultList, is prepended to it, so that a platform can put its plugins in the default configuration file and users can still add more on the command line without overwriting them. Duplicate plugins are ignored.[3][4]

spark-submit \
  --jars my-plugin.jar \
  --conf spark.plugins=com.example.MyPlugin \
  app.py

The plugin jar must be on the classpath of both the driver and the executors, because Spark creates one instance in each.

What are the parts of the plugin API?

A SparkPlugin returns two optional components. The driver component has a single instance per application, inside the driver; the executor component has one instance in each executor that Spark starts.[1]

DriverPlugin (since 3.0.0) has these methods:[5]

  • init(SparkContext, PluginContext) runs early in driver startup, before the task scheduler is initialized, and blocks startup until it returns. The map it returns is passed to every executor plugin's init.
  • registerMetrics(appId, PluginContext) runs later, once the application ID is known. Metrics added to the context's registry by then are published as a metrics source named after the plugin.
  • receive(Object) handles messages sent from executor plugins.
  • shutdown() runs when the driver stops.

ExecutorPlugin (since 3.0.0) has these methods:[6]

  • init(PluginContext, Map<String, String> extraConf) runs during executor startup and blocks it. Executor metrics must be registered here; metrics registered later may not show up.
  • onTaskStart(), onTaskSucceeded() and onTaskFailed(TaskFailedReason) (all since 3.1.0) run on the task's own thread. The documentation warns against expensive work here, such as calls to remote services, because they run for every task.
  • shutdown() runs during executor shutdown and blocks it.

PluginContext gives both sides a Dropwizard MetricRegistry, the SparkConf, the executor ID, the host name and the resources assigned to the process. On executors, send(Object) sends a message to the driver plugin without waiting, and ask(Object) waits for a reply, up to spark.rpc.askTimeout.[7]

Example: counting failed tasks per executor

package com.example

import java.util.{Collections, Map => JMap}
import com.codahale.metrics.Counter
import org.apache.spark.TaskFailedReason
import org.apache.spark.api.plugin._

class TaskFailurePlugin extends SparkPlugin {
  override def driverPlugin(): DriverPlugin = null   // no driver-side component

  override def executorPlugin(): ExecutorPlugin = new ExecutorPlugin {
    private var failures: Counter = _

    override def init(ctx: PluginContext, extraConf: JMap[String, String]): Unit = {
      failures = ctx.metricRegistry().counter("failedTasks")
    }

    override def onTaskFailed(reason: TaskFailedReason): Unit = failures.inc()
  }
}

Loaded with --conf spark.plugins=com.example.TaskFailurePlugin, the counter appears in each executor's metrics under the plugin.<Plugin Class Name> namespace, alongside Spark's own executor metrics.[4]

What is built on the Spark plugin API?

The plugin API is the entry point for several projects that replace or extend Spark's execution:

  • Apache Gluten offloads compute-intensive SQL processing to native engines such as Velox and ClickHouse while reusing Spark's control flow. It translates Spark physical plans into Substrait plans and is enabled with spark.plugins=org.apache.gluten.GlutenPlugin.[8] Gluten graduated from the Apache Incubator on 2026-02-18.[9]
  • DataFusion Comet (Apache DataFusion Comet), which describes itself as an accelerator for Apache Spark that runs on commodity hardware, is enabled with spark.plugins=org.apache.spark.CometPlugin. Its CometPlugin class implements both a driver and an executor plugin.[10][11]
  • RAPIDS Accelerator for Apache Spark, from NVIDIA, runs SQL operations on GPUs and is enabled with spark.plugins=com.nvidia.spark.SQLPlugin.[12]

Spark plugin vs Spark listener

Spark plugin Spark listener
Runs on Driver and every executor[1] Driver only, on the listener bus[13]
Timing Synchronous; init blocks startup[5][6] Asynchronous; events can be dropped if a queue is full
Can publish metrics Yes, through the metrics system[7] No built-in metrics registry
Configured with spark.plugins[3] spark.extraListeners[3]
Typical use Native or GPU execution engines, executor-side instrumentation Lineage, auditing, job monitoring

See also

References

  1. ↑ 1.0 1.1 1.2 SparkPlugin.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  2. ↑ SPARK-29397: Create new plugin interface for driver and executor plugins. Apache Software Foundation.Retrieved 2026-11-23.
  3. ↑ 3.0 3.1 3.2 config/package.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  4. ↑ 4.0 4.1 Monitoring and Instrumentation (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  5. ↑ 5.0 5.1 DriverPlugin.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  6. ↑ 6.0 6.1 ExecutorPlugin.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  7. ↑ 7.0 7.1 PluginContext.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  8. ↑ Apache Gluten README (v1.7.0). Apache Software Foundation.Retrieved 2026-11-23.
  9. ↑ Gluten Project Incubation Status. Apache Incubator.Retrieved 2026-11-23.
  10. ↑ Apache DataFusion Comet README (1.2.0). Apache Software Foundation.Retrieved 2026-11-23.
  11. ↑ Plugins.scala (Comet 1.2.0). Apache Software Foundation.Retrieved 2026-11-23.
  12. ↑ RAPIDS Accelerator for Apache Spark Configuration (v26.10.0). NVIDIA.Retrieved 2026-11-23.
  13. ↑ LiveListenerBus.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.