concept cluster in category spark
appears as: cluster, clusters, cluster, A cluster

This is an excerpt from Manning's book Spark in Action, Second Edition.
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
SparkSessionobject in your application (also called the driver ) coordinates the processes. There is a uniqueSparkSessionfor your application, whether you are in local mode or have 10,000 nodes. TheSparkSessionis created when you build your session, as in the following: