Updated on 2022-12-09 GMT+08:00

Getting Started with Spark

This section describes how to use Spark to submit a SparkPi job. SparkPi, a typical Spark job, is used to calculate the value of Pi (π).

Procedure

  1. Prepare the SparkPi program.

    Multiple open source Spark sample programs are provided, including SparkPi. Click https://archive.apache.org/dist/spark/spark-2.1.0/spark-2.1.0-bin-hadoop2.7.tgz to download the Spark program package.

    Decompress the software package to obtain the spark-examples_2.11-2.1.0.jar file, the sample program package, in the spark-2.1.0-bin-hadoop2.7/examples/jars directory. The spark-examples_2.11-2.1.0.jar sample program package contains the SparkPi program.

  2. Upload data to OBS.

    1. Log in to OBS Console.
    2. Choose Parallel File System > Create Parallel File System to create a file system named sparkpi.

      sparkpi is only an example. The file system name must be globally unique. Otherwise, the parallel file system fails to be created. Use the default values for other parameters.

    3. Click the file system name sparkpi and click Files.
    4. Click Create Folder to create the program folder. Figure 1 shows the folder.
      Figure 1 Folder list
    5. Go to the program folder, click Upload Object, select the program package downloaded in 1 from the local PC, and set Storage Class to Standard.

  3. Log in to the MRS console. In the left navigation pane, choose Clusters > Active Clusters, and click a cluster name.
  4. Submit the SparkPi job.

    On the details page of the MRS cluster, click the Jobs tab. On this tab page, click Create. The Create Job dialog box is displayed. For details, see Running a Spark Job.
    Figure 2 sparkPi job
    • Set Type to SparkSubmit.
    • Set Name to sparkPi.
    • Set Program Path to the path where programs are stored on OBS, for example, obs://sparkpi/program/spark-examples_2.11-2.1.0.jar.
    • In Program Parameter, select --class for Parameter and set Value to org.apache.spark.examples.SparkPi.
    • Set Parameters to 10.
    • Leave Service Parameter blank.

    A job can be submitted only when the cluster is in the Running state.

    After a job is submitted successfully, it is in the Accepted state by default. You do not need to manually execute the job.

  5. View the job execution result.

    1. Go to the Jobs tab page and view job execution status.

      The job execution takes a while. After the jobs are complete, refresh the job list.

      Once a job has succeeded or failed, you cannot execute it again. However, you can add or copy a job, and set job parameters to submit a job again.

    2. Go to the native Yarn page and view the job output information.
      1. On the Jobs tab page, locate the row that contains the target job and click View Details in the Operation column to obtain the actual job ID.
        Figure 3 Actual job ID
      2. Log in to Manager and choose Services > Yarn > ResourceManager WebUI > ResourceManager (Active). The Yarn page is displayed.
      3. Click the ID corresponding to the actual job ID.
        Figure 4 Yarn web UI
      4. Click Logs in the job log area.
        Figure 5 sparkPi job logs
      5. Click here to obtain more detailed logs.
        Figure 6 More detailed logs of sparkPi jobs
      6. Obtain the job execution result.
        Figure 7 sparkPi job execution result