本期内容:spa
1,Spark Streaming资源动态分配资源
2,Spark Streaming动态控制消费速率spark
Spark Streaming处理数据有高峰期和低峰期,若是处理不一样的时期资源占用同样的话,在低峰值就会存在资源的浪费。io
在SparkContext中能够经过设置spark.dynamicAllocation.enabled来开启资源动态分配。原理
读取配置文件中spark.dynamicAllocation.enabled和spark.executor.instances的值。配置
ExecutorAllocationManager类中能够设置Executor最大个数和最小个数,初始个数。定时器
实现资源动态分配的原理是定时器每隔固定的周期不断去扫描Executor的状况,正在运行的Stage中的Task信息,若是一段时间内某个Executor上的没有一个Task任务运行,就可能把这个Executor移除掉。若是须要增长Executor则让Worker启动Executor。im