Spark 的基本使用
1、执行第一个 Spark 程序
利用 Spark 自带的例子程序执行一个求 PI(蒙特卡洛算法)的程序:
$SPARK_HOME/bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://hadoop02:7077 \
--executor-memory 512m \
--total-executor-cores 2 \
$SPARK_HOME/examples/jars/spark-examples_2.11-2.3.0.jar \
100
2、启动 Spark Shell
启动命令:
$SPARK_HOME/bin/spark-shell \
--master spark://hadoop02:7077,hadoop04:7077 \
--executor-memory 512M \
--total-executor-cores 2
注意上图中的 cores 参数,是 0,那么以后这个 spark shell 中运行的代码是不能执行成功的。 千万注意。必要要把 cpu cores 和 memory 设置合理
1、 executor memory 不能超过虚拟机的内存
2、 cpu cores 不要超过 spark 集群能够提供的总 cpu cores,否则会使用全部。最好不要使用全部。否则其他程序由于没有 cpu core 可用,就不能正常运