Develop and periodically schedule Spark jobs on an EMR Serverless Spark cluster in DataWorks. Spark supports complex in-memory computing, making it well suited for large-scale, low-latency data analytics.
Prerequisites
-
Compute resource limitations: Only bound EMR Serverless Spark compute resources are supported. You must ensure that the resource group and the compute resource can communicate over the network.
-
Resource group constraints: This task runs only in a Serverless resource group.
-
(Optional, for RAM users) The Resource Access Management (RAM) user for task development must be added to the workspace and assigned the Development or Workspace Administrator role (this role includes extensive permissions and must be granted with caution). For more information, see Add workspace members.
If you are using a root account, skip this step.
Create a node
For instructions, see Create a node.
Develop the node
Before you develop a Serverless Spark Batch job, develop the Spark job code in E-MapReduce (EMR) and compile it into a JAR package. For guidance on Spark development, see Spark tutorials.
Choose the approach that best fits your use case:
Option 1: Upload and reference EMR JAR
Upload the compiled JAR package to DataWorks as an EMR JAR resource. This approach works for JAR packages smaller than 500 MB.
-
Create an EMR JAR resource.
-
In the left-side navigation pane, click the
icon to go to the Resource Management page. -
On the Resource Management page, click the
icon, select , and name the resource spark-examples_2.11-2.4.0.jar. -
Click Click Upload and upload the spark-examples_2.11-2.4.0.jar file.
-
Select a Storage Path, Data Sources, and Resource Group.
ImportantFor the data source, you must select the bound EMR Serverless Spark cluster.
-
Click Save.
-
-
Reference the EMR JAR resource.
-
Open the Serverless Spark Batch node that you created and stay on the code editor page.
-
In the Resource Management pane on the left, find the resource you want to use, right-click it, and select Insert Resource Path.
-
The resource is successfully referenced when the following code is automatically added to the code editor of the Serverless Spark Batch node:
##@resource_reference{"spark-examples_2.11-2.4.0.jar"} spark-examples_2.11-2.4.0.jarIn the preceding code, spark-examples_2.11-2.4.0.jar is the name of the EMR JAR resource that you uploaded.
-
Modify the node code by adding the spark-submit command. The following example shows the modified code.
Important-
Follow the example exactly. Do not add comments, as they cause the node to fail.
-
For EMR Serverless Spark, you do not need to set the
deploy-modeparameter for thespark-submitcommand. Onlyclustermode is supported.
##@resource_reference{"spark-examples_2.11-2.4.0.jar"} spark-submit --class org.apache.spark.examples.SparkPi spark-examples_2.11-2.4.0.jar 100Command
Description
classThe main class of the application in the JAR file. In this example, the value is
org.apache.spark.examples.SparkPi.NoteFor more information about parameters, see Submit a job using spark-submit.
-
-
Option 2: Reference OSS resource
Reference a resource stored in Object Storage Service (OSS). DataWorks automatically loads the specified OSS resource at runtime. Use this approach when an EMR job requires JAR dependencies or depends on scripts.
-
Develop the JAR resource: This topic uses SparkWorkOSS-1.0-SNAPSHOT-jar-with-dependencies.jar as an example.
-
Upload the JAR resource.
-
Log on to the OSS console. In the left-side navigation pane, click buckets.
-
Click the name of the target bucket to go to the file management page.
-
Click Create Directory to create a directory to store the JAR resource.
-
Go to the directory and upload the
SparkWorkOSS-1.0-SNAPSHOT-jar-with-dependencies.jarfile to the bucket.
-
-
Reference the JAR resource.
-
In the code editor for the Serverless Spark Batch node that you created, write the code to reference the JAR resource.
ImportantIn the following code, the OSS bucket name is
mybucketand the directory isemr. Replace them with your actual values.spark-submit --class com.aliyun.emr.example.spark.SparkMaxComputeDemo oss://mybucket/emr/SparkWorkOSS-1.0-SNAPSHOT-jar-with-dependencies.jarParameters:
Parameter
Description
classThe fully qualified name of the main class to run.
ossfile pathThe format is
oss://{bucket}/{object}.-
bucket: The OSS container that stores objects. Each bucket has a unique name. You can log on to the OSS console to view all buckets under your account.
-
object: A file or path stored in a bucket.
NoteFor more information about parameters, see Submit a job using spark-submit.
-
-
Debug the node
-
In the Run Configuration pane, configure settings such as Compute resource and resource group.
Parameter
Description
Compute resource
Select a bound EMR Serverless Spark compute resource. If none are available, select Create Compute Resource from the drop-down list.
resource group
Select a resource group that is bound to the workspace.
Script parameters
Define variables in the node's code by using the
${Parameter name}format. Then define the Parameter name and Parameter Value in the Script Parameters section. At runtime, DataWorks replaces these variables with the specified values. For more information, see Scheduling parameters.ServerlessSpark node parameters
Runtime parameters for the Spark program. The following types are supported:
-
Custom runtime parameters for DataWorks. For more information, see Appendix: DataWorks parameters.
-
Spark built-in properties. For more information, see Open-source Spark properties and Custom Spark Conf parameters.
The configuration format is:
"spark.eventLog.enabled": false. DataWorks automatically adds this setting to the code submitted to Serverless Spark in the--conf key=valueformat.NoteYou can set global Spark parameters at the workspace level and specify whether they take priority over parameters set within a specific module. For details, see Configure global Spark parameters.
-
-
In the toolbar at the top of the node editor, click Run.
ImportantBefore you publish, you must synchronize the ServerlessSpark node parameters in the Run Configuration to the ServerlessSpark node parameters in the Scheduling Settings.
Next steps
-
Configure node scheduling: If you need to run a node periodically, configure its Scheduling Policy in the Scheduling Settings panel on the right.
-
Publish a node: To run a task in the production environment, click the
icon to publish the node. A node runs on schedule only after it is published to the production environment. -
Task O&M: After a task is published, you can monitor the status of its periodic runs in the Operation Center. For more information, see Get started with Operation Center.
Related documentation
Appendix: DataWorks parameters
|
Parameter |
Description |
|
SERVERLESS_QUEUE_NAME |
The resource queue to which the job is submitted. By default, jobs are submitted to the Default Resource Queue configured for the cluster under Clusters in the Management Center. To isolate and manage resources, you can add queues. For more information, see Manage resource queues. Configuration methods:
|