1、依次启动hdfs(根路径下:start-all.sh)、zookeeper(根路径下:./zkmanager start)、spark-shell(spark的sbin路径下)
./spark-shell --master spark://hdp-1:7077 --executor-memory 500m --total-executor-cores 1
2、读取hdfs上的文件:
var lines = sc.textFile("hdfs://hdp-1:9000/spark/hello.txt")
3、将读到的文件放入缓存
var cached = lines.cache
4、发出action
cached.count
lines.count
cached.count是没有在缓冲区执行
lines.count是在缓冲区执行
5、观察spark的job执行时长
其中job id中的5和4 的执行时间快慢做比较,4是在缓冲区执行所用的时间,5是没有在缓冲区所用的时间
6、缓存应用扩展