Cloud Dataproc is a fast, easy-to-use, fully-managed cloud service for running Apache Spark and Apache Hadoop clusters in a simpler, more cost-efficient way. Operations that used to take hours or days take seconds or minutes instead. Create Cloud Dataproc clusters quickly and resize them at any time, so you don't have to worry about your data pipelines outgrowing your clusters.
This demo shows you how to use the Google Cloud Platform (GCP) Console to create a Google Cloud Dataproc cluster, run a simple Apache Spark job in the cluster, then modify the number of workers in the cluster.
To create a Dataproc cluster in GCP, the Cloud Dataproc API must be enabled. To confirm the API is enabled:
Click Navigation menu > APIs & Services > Library:
Type Cloud Dataproc in the Search for APIs & Services dialog. The console will display the Cloud Dataproc API in the search results.
Click on Cloud Dataproc API to display the status of the API. If the API is not already enabled, click the Enable button.
If the API's enabled, you're good to go.
In the Cloud Platform Console, select Navigation menu > Dataproc > Clusters, then click Create cluster.
Set the following fields for your cluster. Accept the default values for all other fields.
Field | Value |
---|---|
Name | example-cluster |
Region | global |
Zone | us-central1-a |
Click Create to create the cluster.
Your new cluster will appear in the Clusters list. It may take a few minutes to create, the cluster Status shows as "Provisioning" until the cluster is ready to use, then changes to "Running."
To run a sample Spark job:
Click Jobs in the left pane to switch to Dataproc's jobs view, then click Submit job:
Set the following fields to update Job. Accept the default values for all other fields.
Field | Value |
---|---|
Cluster | example-cluster |
Job type | Spark |
Main class or jar | org.apache.spark.examples.SparkPi |
Arguments | 1000 (This sets the number of tasks.) |
Jar file | file:///usr/lib/spark/examples/jars/spark-examples.jar |
Click Submit.
How the job calculates Pi: The Spark job estimates a value of Pi using the Monte Carlo method. It generates x,y points on a coordinate plane that models a circle enclosed by a unit square. The input argument (1000) determines the number of x,y pairs to generate; the more pairs generated, the greater the accuracy of the estimation. This estimation leverages Cloud Dataproc worker nodes to parallelize the computation. For more information, see Estimating Pi using the Monte Carlo Method and see JavaSparkPi.java on GitHub.
Your job should appear in the Jobs list, which shows your project's jobs with its cluster, type, and current status. Job status displays as Running, and then Succeeded after it completes.
To see your completed job's output:
Click the job ID in the Jobs list.
Check Line wrapping or scroll all the way to the right to see the calculated value of Pi. Your output, with Line wrapping checked should show the value of Pi.
Your job has successfully calculated a rough value for pi!
To change the number of worker instances in your cluster:
-
Select Clusters in the left navigation pane to return to the Dataproc Clusters view.
-
Click example-cluster in the Clusters list. By default, the page displays an overview of your cluster's CPU usage.
-
Click Configuration to display your cluster's current settings.
-
Click Edit. The number of worker nodes is now editable.
-
Enter 4 in the Worker nodes field.
-
Click Save.
Your cluster is now updated. Check out the number of VM instances in the cluster
To rerun the job with the updated cluster, you would click Jobs in the left pane, then click SUBMIT JOB.
Set the same fields you set in the Submit a job section:
Field | Value |
---|---|
Cluster | example-cluster |
Job type | Spark |
Main class or jar | org.apache.spark.examples.SparkPi |
Arguments | 1000 (This sets the number of tasks.) |
Jar file | file:///usr/lib/spark/examples/jars/spark-examples.jar |
Click Submit.
Now you know how to use the Google Cloud Platform Console to create and update a Dataproc cluster and then submit a job in that cluster.