Spark编程指南--Shuffle

Certain operations within Spark trigger an event known as the shuffle. The shuffle is Spark’s mechanism for re-distributing data so that it’s grouped differently across partitions. This typically involves copying data across executors and machines, making the shuffle a complex and costly operation.

Spark内的某些操作会触发称为shuffle的事件。 shuffle是Spark的重新分布数据的机制,因此它在分区之间的分组不同。 这通常涉及将数据复制到执行器和机器上,从而使shuffle成为复杂而昂贵的操作。

背景
To understand what happens during the shuffle we can consider the example of the reduceByKey operation. The reduceByKey operation generates a new RDD where all values for a single key are combined into a tuple - the key and the result of executing a reduce function against all values associated with that key. The challenge is that not all values for a single key necessarily reside on the same partition, or even the same machine, but they must be co-located to compute the result.
要了解shuffle中会发生什么,我们可以考虑reduceByKey操作的示例。 reduceByKey操作生成一个新的RDD,其中单个key的所有值都被组合成一个元组 - key和执行reduce函数的结果与所有与该key关联的value。 挑战在于,并不是单个key的所有值都必须驻留在同一个分区上,甚至是同一个机器上,但它们必须位于同一位置才能计算结果。

In Spark, data is generally not distributed across partitions to be in the necessary place for a specific operation. During computations, a single task will operate on a single partition - thus, to organize all the data for a single reduceByKey reduce task to execute, Spark needs to perform an all-to-all operation. It must read from all partitions to find all the values for all keys, and then bring together values across partitions to compute the final result for each key - this is called the shuffle.
在Spark中,数据通常不会跨分区分布,以便在特定操作的必要位置。 在计算过程中,单个任务将在单个分区上运行 - 因此,为了执行单个reduceByKey任务来组织所有数据,Spark需要执行多对多的操作。 它必须从所有分区中读取以查找所有键的所有值,然后将分区中的值汇集在一起,以计算每个键的最终结果 - 这称为shuffle。

Although the set of elements in each partition of newly shuffled data will be deterministic, and so is the ordering of partitions themselves, the ordering of these elements is not. If one desires predictably ordered data following shuffle then it’s possible to use:

虽然新shuffle后数据的每个分区中的元素集将是确定性的,分区本身的排序也是如此,但是这些元素的排序不是。 如果一个人想要shuffle之后可预测的有序数据,那么可以使用:

–mapPartitions to sort each partition using, for example, .sorted
–repartitionAndSortWithinPartitions to efficiently sort partitions while simultaneously repartitioning
–sortBy to make a globally ordered RDD

mapPartitions以使用例如.sorted对每个分区进行排序
repartitionAndSortWithinPartitions有效地对分区进行分类,同时重新分区
sortBy来制作一个全局排序的RDD

Operations which can cause a shuffle include repartition operations like repartition and coalesce, ‘ByKey operations (except for counting) like groupByKey and reduceByKey, and join operations like cogroup and join.

可能导致shuffle 的操作包括重新分区操作,如重新分区和合并,“ByKey操作(除了计数),如groupByKey和reduceByKey),并加入像cogroup和join这样的操作。

Performance Impact
性能影响
The Shuffle is an expensive operation since it involves disk I/O, data serialization, and network I/O. To organize data for the shuffle, Spark generates sets of tasks - map tasks to organize the data, and a set of reduce tasks to aggregate it. This nomenclature comes from MapReduce and does not directly relate to Spark’s map and reduce operations.
Shuffle 是一项昂贵的操作,因为它涉及磁盘I / O,数据串行化和网络I / O。 要组织随机播放的数据,Spark会生成一组任务 - 映射任务以组织数据,以及一组缩减任务以进行汇总。 这个命名法来自于MapReduce,并不直接与Spark的Map和Reduce操作有关。

Internally, results from individual map tasks are kept in memory until they can’t fit. Then, these are sorted based on the target partition and written to a single file. On the reduce side, tasks read the relevant sorted blocks.
在内部,单独的map任务的结果将保存在内存中,直到它们不适合为止。 然后,这些根据目标分区进行排序并写入单个文件。 在reduce时,任务读取相关的排序块。

Certain shuffle operations can consume significant amounts of heap memory since they employ in-memory data structures to organize records before or after transferring them. Specifically, reduceByKey and aggregateByKey create these structures on the map side, and ‘ByKey operations generate these on the reduce side. When data does not fit in memory Spark will spill these tables to disk, incurring the additional overhead of disk I/O and increased garbage collection.
某些shuffle 操作可能会占用大量的堆内存,因为它们在传输之前或之后使用内存中的数据结构来组织记录。 具体来说,reduceByKey和aggregateByKey在map上创建这些结构,而ByKey操作会在reduce方面生成这些结构。 当数据不适合内存时,Spark会将这些表溢出到磁盘,导致磁盘I / O的额外开销和增加的垃圾回收。

Shuffle also generates a large number of intermediate files on disk. As of Spark 1.3, these files are preserved until the corresponding RDDs are no longer used and are garbage collected. This is done so the shuffle files don’t need to be re-created if the lineage is re-computed. Garbage collection may happen only after a long period of time, if the application retains references to these RDDs or if GC does not kick in frequently. This means that long-running Spark jobs may consume a large amount of disk space. The temporary storage directory is specified by the spark.local.dir configuration parameter when configuring the Spark context.
Shuffle 还会在磁盘上生成大量的中间文件。 从Spark 1.3开始,这些文件将被保留,直到相应的RDD不再使用并被垃圾回收。 这样做,所以如果重新计算谱系,则不需要重新创建Shuffle 文件。 如果应用程序保留对这些RDD的引用或GC不频繁启动,垃圾收集可能仅在长时间之后才会发生。 这意味着长时间运行的Spark作业可能会消耗大量的磁盘空间。 当配置Spark上下文时,临时存储目录由spark.local.dir配置参数指定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本火锅店点餐系统采用Java语言和Vue技术,框架采用SSM,搭配Mysql数据库,运行在Idea里,采用小程序模式。本火锅店点餐系统提供管理员、用户两种角色的服务。总的功能包括菜品的查询、菜品的购买、餐桌预定和订单管理。本系统可以帮助管理员更新菜品信息和管理订单信息,帮助用户实现在线的点餐方式,并可以实现餐桌预定。本系统采用成熟技术开发可以完成点餐管理的相关工作。 本系统的功能围绕用户、管理员两种权限设计。根据不同权限的不同需求设计出更符合用户要求的功能。本系统中管理员主要负责审核管理用户,发布分享新的菜品,审核用户的订餐信息和餐桌预定信息等,用户可以对需要的菜品进行购买、预定餐桌等。用户可以管理个人资料、查询菜品、在线点餐和预定餐桌、管理订单等,用户的个人资料是由管理员添加用户资料时产生,用户的订单内容由用户在购买菜品时产生,用户预定信息由用户在预定餐桌操作时产生。 本系统的功能设计为管理员、用户两部分。管理员为菜品管理、菜品分类管理、用户管理、订单管理等,用户的功能为查询菜品,在线点餐、预定餐桌、管理个人信息等。 管理员负责用户信息的删除和管理,用户的姓名和手机号都可以由管理员在此功能里看到。管理员可以对菜品的信息进行管理、审核。本功能可以实现菜品的定时更新和审核管理。本功能包括查询餐桌,也可以发布新的餐桌信息。管理员可以查询已预定的餐桌,并进行审核。管理员可以管理公告和系统的轮播图,可以安排活动。管理员可以对个人的资料进行修改和管理,管理员还可以在本功能里修改密码。管理员可以查询用户的订单,并完成菜品的安排。 当用户登录进系统后可以修改自己的资料,可以使自己信息的保持正确性。还可以修改密码。用户可以浏览所有的菜品,可以查看详细的菜品内容,也可以进行菜品的点餐。在本功能里用户可以进行点餐。用户可以浏览没有预定出去的餐桌,选择合适的餐桌可以进行预定。用户可以管理购物车里的菜品。用户可以管理自己的订单,在订单管理界面里也可以进行查询操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值