<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_resource_profiles</id>
	<title>Spark resource profiles - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_resource_profiles"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_resource_profiles&amp;action=history"/>
	<updated>2026-12-06T00:13:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Spark_resource_profiles&amp;diff=195&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_resource_profiles&amp;diff=195&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:56Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Spark resource profiles&lt;br /&gt;
| also_known_as   = Stage-level scheduling, ResourceProfile, accelerator-aware scheduling&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| introduced      = Apache Spark 3.1 (stage-level scheduling); Apache Spark 3.0 (GPU and custom resource scheduling)&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ResourceProfileBuilder&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ExecutorResourceRequests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TaskResourceRequests&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RDD.withResources&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Executor]], [[GPU acceleration in Spark]], [[Shuffle]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/configuration.md, docs/running-on-yarn.md, docs/running-on-kubernetes.md, docs/spark-standalone.md, python/pyspark/resource/, python/pyspark/core/rdd.py, python/pyspark/sql/dataframe.py), Apache JIRA SPARK-24615, SPARK-27495, SPARK-29150, SPARK-39853, SPARK-45495 and SPARK-46812, and the Spark 3.0.0, 3.1.1 and 4.0.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], a &amp;#039;&amp;#039;&amp;#039;resource profile&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt;) is a set of executor and task resource requirements, such as cores, memory and GPUs, that Spark applies to one stage of a job instead of to the whole application.&amp;lt;ref name=&amp;quot;conf&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/configuration.html |title=Spark Configuration (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The feature is called &amp;#039;&amp;#039;&amp;#039;stage-level scheduling&amp;#039;&amp;#039;&amp;#039; and was added in Spark 3.1.&amp;lt;ref name=&amp;quot;r311&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-1-1.html |title=Spark Release 3.1.1 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It builds on the accelerator-aware scheduling of Spark 3.0, which lets an application request GPUs and other custom resources for its [[executor]]s and tasks.&amp;lt;ref name=&amp;quot;r300&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-0-0.html |title=Spark Release 3.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What problem do resource profiles solve? ==&lt;br /&gt;
Without resource profiles, a Spark application asks for one kind of executor at startup and keeps it for every stage. The Spark documentation gives the case of an ETL stage that needs only CPUs followed by a machine learning stage that needs GPUs: with stage-level scheduling, the application can request GPU executors only when the ML stage runs, instead of holding idle GPUs during the ETL stage.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does GPU scheduling work in Apache Spark? ==&lt;br /&gt;
Spark 3.0 added accelerator-aware scheduling under the SPARK-24615 proposal, part of Project Hydrogen.&amp;lt;ref name=&amp;quot;r300&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira24615&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-24615 |title=SPARK-24615: SPIP: Accelerator-aware task scheduling for Spark |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A resource is identified by a name such as &amp;lt;code&amp;gt;gpu&amp;lt;/code&amp;gt;, and Spark schedules its individual addresses (for example GPU indexes) to tasks. The cluster manager must support and be configured for the resource; the feature is not available in local mode.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark GPU settings, all added in Spark 3.0.0, are:&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.executor.resource.gpu.amount&amp;lt;/code&amp;gt; (default 0): GPUs per executor.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.executor.resource.gpu.discoveryScript&amp;lt;/code&amp;gt; (no default): a script the executor runs at startup; it prints a JSON object with the resource name and an array of addresses. It is required on YARN and Kubernetes.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.executor.resource.gpu.vendor&amp;lt;/code&amp;gt; (no default): Kubernetes only; the device plugin vendor and domain, for example &amp;lt;code&amp;gt;nvidia.com&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;amd.com&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.task.resource.gpu.amount&amp;lt;/code&amp;gt; (default 1): GPUs per task. Fractional values up to 0.5 let several tasks share one GPU; 0.25 means four tasks per GPU.&lt;br /&gt;
* &amp;lt;code&amp;gt;spark.driver.resource.gpu.amount&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.driver.resource.gpu.discoveryScript&amp;lt;/code&amp;gt;: the same for the driver.&lt;br /&gt;
&lt;br /&gt;
The Spark source tree ships a sample GPU discovery script, &amp;lt;code&amp;gt;examples/src/main/scripts/getGpusResources.sh&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;script&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/examples/src/main/scripts/getGpusResources.sh |title=getGpusResources.sh (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Inside a task, &amp;lt;code&amp;gt;TaskContext.get().resources()&amp;lt;/code&amp;gt; returns the addresses Spark assigned; Spark does not use the GPU itself, so the user code or the ML library must use those addresses.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is a resource profile built? ==&lt;br /&gt;
A resource profile is built from two request objects. &amp;lt;code&amp;gt;ExecutorResourceRequests&amp;lt;/code&amp;gt; sets executor cores, memory, memory overhead, PySpark memory, off-heap memory and custom resources; &amp;lt;code&amp;gt;TaskResourceRequests&amp;lt;/code&amp;gt; sets the CPUs and custom resources each task needs. &amp;lt;code&amp;gt;ResourceProfileBuilder.require()&amp;lt;/code&amp;gt; adds both, and &amp;lt;code&amp;gt;build&amp;lt;/code&amp;gt; returns the &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;pyreq&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/resource/requests.py |title=pyspark/resource/requests.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pyprof&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/resource/profile.py |title=pyspark/resource/profile.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The same classes exist in Scala and Java in the &amp;lt;code&amp;gt;org.apache.spark.resource&amp;lt;/code&amp;gt; package.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;RDD.withResources(profile)&amp;lt;/code&amp;gt; attaches a profile to an RDD, and the stage that computes that RDD uses it. The RDD API for stage-level scheduling was tracked as SPARK-29150 and released in Spark 3.1; the PySpark &amp;lt;code&amp;gt;withResources&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ResourceProfileBuilder&amp;lt;/code&amp;gt; APIs are marked &amp;quot;new in version 3.1.0&amp;quot; and &amp;quot;evolving&amp;quot;.&amp;lt;ref name=&amp;quot;jira29150&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-29150 |title=SPARK-29150: Update RDD API for Stage level scheduling |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pyrdd&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/api/python/reference/api/pyspark.RDD.withResources.html |title=pyspark.RDD.withResources (PySpark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;pyprof&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example in PySpark ==&lt;br /&gt;
The example asks for executors with 4 cores, 8 GiB of memory and one GPU for one stage, and lets four tasks share each GPU. It assumes dynamic allocation and a GPU discovery script on the executor image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.resource import (&lt;br /&gt;
    ExecutorResourceRequests,&lt;br /&gt;
    TaskResourceRequests,&lt;br /&gt;
    ResourceProfileBuilder,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
ereqs = (ExecutorResourceRequests()&lt;br /&gt;
         .cores(4)&lt;br /&gt;
         .memory(&amp;quot;8g&amp;quot;)&lt;br /&gt;
         .resource(&amp;quot;gpu&amp;quot;, 1, &amp;quot;/opt/spark/examples/src/main/scripts/getGpusResources.sh&amp;quot;))&lt;br /&gt;
treqs = TaskResourceRequests().cpus(1).resource(&amp;quot;gpu&amp;quot;, 0.25)&lt;br /&gt;
gpu_profile = ResourceProfileBuilder().require(ereqs).require(treqs).build&lt;br /&gt;
&lt;br /&gt;
rdd = spark.sparkContext.parallelize(range(1000), 8)&lt;br /&gt;
result = rdd.withResources(gpu_profile).mapPartitions(lambda it: [sum(it)]).collect()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In PySpark, &amp;lt;code&amp;gt;build&amp;lt;/code&amp;gt; is a property, not a method.&amp;lt;ref name=&amp;quot;pyprof&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which cluster managers support stage-level scheduling? ==&lt;br /&gt;
In Spark 4.3, stage-level scheduling works on YARN, Kubernetes and Spark standalone.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt; Spark 3.1 shipped it with Kubernetes support listed as a separate item (SPARK-33288) under the SPARK-27495 umbrella.&amp;lt;ref name=&amp;quot;r311&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira27495&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-27495 |title=SPARK-27495: SPIP: Support Stage level resource configuration and scheduling |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Cluster manager !! With dynamic allocation !! Without dynamic allocation&lt;br /&gt;
|-&lt;br /&gt;
| YARN&lt;br /&gt;
| New executors per profile; each profile id becomes a YARN container priority&amp;lt;ref name=&amp;quot;yarn&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-yarn.html |title=Running Spark on YARN (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Task requirements only, on the startup executors&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Kubernetes&lt;br /&gt;
| New executors per profile; requires &amp;lt;code&amp;gt;spark.dynamicAllocation.shuffleTracking.enabled&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;k8s&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/running-on-kubernetes.html |title=Running Spark on Kubernetes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Task requirements only (SPARK-45495, Spark 3.5.1 and 4.0.0)&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira45495&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-45495 |title=SPARK-45495: Support stage level task resource profile for k8s cluster when dynamic allocation disabled |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Standalone&lt;br /&gt;
| New executors per profile; only executor memory, cores and custom resources take effect&amp;lt;ref name=&amp;quot;standalone&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-standalone.html |title=Spark Standalone Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Task requirements only (SPARK-39853, Spark 3.4.0)&amp;lt;ref name=&amp;quot;standalone&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira39853&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-39853 |title=SPARK-39853: Support stage level schedule for standalone cluster when dynamic allocation is disabled |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Why does stage-level scheduling need dynamic allocation? ==&lt;br /&gt;
A profile that changes executor resources needs new executors, and Spark gets them through dynamic allocation. With dynamic allocation on, Spark acquires new executors for each profile, and a task runs only on an executor created with exactly its profile; unused executors time out under the normal dynamic allocation rules. With dynamic allocation off, tasks with different task requirements share the executors of the default profile (&amp;lt;code&amp;gt;DEFAULT_RESOURCE_PROFILE&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Kubernetes, shuffle tracking keeps executors that hold shuffle data, so executors from an earlier profile may not time out. The Spark documentation warns that this can use more cluster resources and, if the cluster runs out, the application can hang; &amp;lt;code&amp;gt;spark.dynamicAllocation.shuffleTracking.timeout&amp;lt;/code&amp;gt; limits this at the cost of possible recomputation.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What happens when two profiles meet in one stage? ==&lt;br /&gt;
By default Spark allows one profile per stage and throws an exception if RDDs with different profiles are combined into the same stage. Setting &amp;lt;code&amp;gt;spark.scheduler.resource.profileMergeConflicts&amp;lt;/code&amp;gt; (default false, since 3.1.0) to true makes Spark merge them into a new profile that takes the maximum of each resource.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Can DataFrames use resource profiles? ==&lt;br /&gt;
The Spark 4.3 configuration guide still describes stage-level scheduling as available &amp;quot;only for the RDD API in Scala, Java, and Python&amp;quot;.&amp;lt;ref name=&amp;quot;conf&amp;quot; /&amp;gt; One exception exists in PySpark: since Spark 4.0.0, &amp;lt;code&amp;gt;DataFrame.mapInPandas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;DataFrame.mapInArrow&amp;lt;/code&amp;gt; take an optional &amp;lt;code&amp;gt;profile&amp;lt;/code&amp;gt; argument with a &amp;lt;code&amp;gt;ResourceProfile&amp;lt;/code&amp;gt; (SPARK-46812).&amp;lt;ref name=&amp;quot;pydf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/dataframe.py |title=pyspark/sql/dataframe.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira46812&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-46812 |title=SPARK-46812: Make mapInPandas / mapInArrow support ResourceProfile (Stage-Level scheduling) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r400&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Other DataFrame and Spark SQL operators run with the application&amp;#039;s default profile.&lt;br /&gt;
&lt;br /&gt;
== What a resource profile is not ==&lt;br /&gt;
A Spark resource profile is not a Kubernetes pod resource request or a YARN container size, although Spark translates it into one. On YARN, Spark converts &amp;lt;code&amp;gt;gpu&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;fpga&amp;lt;/code&amp;gt; to the built-in types &amp;lt;code&amp;gt;yarn.io/gpu&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;yarn.io/fpga&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;yarn&amp;quot; /&amp;gt; On Kubernetes, resources from a pod template apply only to the default profile and are not copied into custom profiles.&amp;lt;ref name=&amp;quot;k8s&amp;quot; /&amp;gt; A resource profile also does not make Spark SQL operators run on a GPU; that is the role of plugins such as the RAPIDS Accelerator, described in [[GPU acceleration in Spark]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[GPU acceleration in Spark]]&lt;br /&gt;
* [[Native execution engine (Spark)]]&lt;br /&gt;
* [[Shuffle]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>