concept cluster in category spark

appears as: cluster, clusters, cluster, A cluster
Spark in Action, Second Edition

This is an excerpt from Manning's book Spark in Action, Second Edition.

Your application, or driver , connects to a Spark cluster. From there, the application tells the cluster what to do: the application drives the cluster. In this scenario, the master starts by loading a CSV file and finishes by saving in a database.

Therefore, unlike me in 1994 working with VB3, you started exploring deployment in chapter 5. However, don’t worry: the tradition is respected, as advanced deployment (including managing clusters, resources, sharing files, and more) is still in chapter 18.

You will first look at an example in which data is generated within and by Spark, avoiding the need to ingest data. Ingesting data in a cluster is a bit more complex than creating a self-generated dataset.

Listing 6.1 Calculating an approximation of π
package net .jgp.books.spark.ch05.lab200_pi_compute_cluster;
...
public class PiComputeClusterApp implements Serializable {
...
     private final class DartMapper
         implements MapFunction<Row, Integer> {
...
    }
 
     private final class DartReducer implements ReduceFunction<Integer> {
...
    }
 
     public static void main(String[] args ) {
      PiComputeClusterApp app = new PiComputeClusterApp();
       app .start(10);
    }
 
     private void start(int slices ) {
       int numberOfThrows = 100000 * slices ;
...
      SparkSession spark = SparkSession #1
            .builder() #1
            .appName( "JavaSparkPi on a cluster" ) #1
            .master( "spark://un:7077" ) #1
            .config( "spark.executor.memory" , "4g" ) #1
            .getOrCreate(); #1
...
      List<Integer> l = new ArrayList<>( numberOfThrows );
       for ( int i = 0; i < numberOfThrows ; i ++) {
         l .add( i );
      }
      Dataset<Row> incrementalDf = spark #2
            .createDataset( l , Encoders.INT()) #2
            .toDF(); #2
...
      Dataset<Integer> dartsDs = incrementalDf #3
            .map( new DartMapper(), Encoders.INT()); #3
...
       int dartsInCircle = dartsDs .reduce( new DartReducer()); #4
...
      System. out .println( "Pi is roughly " +
➥ 4.0 * dartsInCircle / numberOfThrows );
 
       spark .stop();
    }
 }

Spark applications run as independent processes on a cluster. The SparkSession object in your application (also called the driver ) coordinates the processes. There is a unique SparkSession for your application, whether you are in local mode or have 10,000 nodes. The SparkSession is created when you build your session, as in the following:

Figure 18.6 Spark’s workers must be able to access the data. The data can be in files, databases, or streams. Files can be problematic because they may be spread logically around organizations and physically around servers and clusters.