spark多级mapwithstate shuffle问题

8aqjt8rx  于 2021-07-13  发布在  Spark
关注(0)|答案(0)|浏览(571)

我们有一个有状态的多阶段dstream应用程序,其中每个阶段都Map到不同的键。在第一个阶段之后,我们正在经历巨大的无序读写,这种无序读写在大约20个窗口之后不断增长并变得巨大。

  1. val stageOnePartitionCount = 1000
  2. val stageTwoPartitionCount = 1000
  3. val stageThreePartitionCount = 1000
  4. // Very little Shuffle for this stage consistent across all windows
  5. val stageOneDataSet = dataSet
  6. .map(data => (data.key1, data))
  7. .reduceByKey(..., stageOnePartitionCount)
  8. .mapWithState(
  9. StateSpec
  10. .function(...)
  11. .initialState(...) // uses key1
  12. .numPartitions(stageOnePartitionCount)
  13. )
  14. // Shuffle for this stage grows every window and becomes huge after about 20 windows or so..
  15. val stageTwoDataSet = stageOneDataSet
  16. .map(data => (data.key2, data))
  17. .reduceByKey(..., stageTwoPartitionCount)
  18. .mapWithState(
  19. StateSpec
  20. .function(...)
  21. .initialState(...) // uses key2
  22. .numPartitions(stageTwoPartitionCount)
  23. )
  24. // Shuffle for this stage grows every window and becomes huge after about 20 windows or so..
  25. val stageThreeDataSet = stageTwoDataSet
  26. .map(data => (data.key3, data))
  27. .reduceByKey(..., stageThreePartitionCount)
  28. .mapWithState(
  29. StateSpec
  30. .function(...)
  31. .initialState(...) // uses key3
  32. .numPartitions(stageThreePartitionCount)
  33. )
  34. stageThreeDataSet
  35. .foreachRDD(...)

我们正在表演 reduceByKey (合并部分更新)操作 mapWithState 每个阶段中的操作,其中分区计数在它们之间匹配,目的是在 reduceByKey 在传入流上的函数数据将已经在其状态所在的节点中。
那么,是什么触发了第二和第三阶段在每一个经过的窗口中的洗牌指数上升,而第一阶段在所有窗口中几乎没有洗牌的情况下仍然保持性能呢?
注意:查看第二和第三阶段被洗牌(读/写)的数据量,我想知道是否有可能对有状态rdd(包含状态数据)进行洗牌,以便将它们与传入流(在大约20个窗口之后,其大小将比累积状态小得多)一起定位。如果是这种情况,我们如何解决同样的问题。
谢谢你的帮助!!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题