当前位置:网站首页>spark调优(三):持久化减少二次查询
spark调优(三):持久化减少二次查询
2022-07-07 14:13:00 【InfoQ】
1. 起因
2. 优化开始
df = sc.sql(sql)
df1 = df.persist()
df1.createOrReplaceTempView(temp_table_name)
subdf = sc.sql(select * from temp_table_name)

- 默认情况下,性能最高的当然是MEMORY_ONLY,但前提是你的内存必须足够足够大,可以绰绰有余地存放下整个RDD的所有数据。因为不进行序列化与反序列化操作,就避免了这部分的性能开销;对这个RDD的后续算子操作,都是基于纯内存中的数据的操作,不需要从磁盘文件中读取数据,性能也很高;而且不需要复制一份数据副本,并远程传送到其他节点上。但是这里必须要注意的是,在实际的生产环境中,恐怕能够直接用这种策略的场景还是有限的,如果RDD中数据比较多时(比如几十亿),直接用这种持久化级别,会导致JVM的OOM内存溢出异常。
- 如果使用MEMORY_ONLY级别时发生了内存溢出,那么建议尝试使用MEMORY_ONLY_SER级别。该级别会将RDD数据序列化后再保存在内存中,此时每个partition仅仅是一个字节数组而已,大大减少了对象数量,并降低了内存占用。这种级别比MEMORY_ONLY多出来的性能开销,主要就是序列化与反序列化的开销。但是后续算子可以基于纯内存进行操作,因此性能总体还是比较高的。此外,可能发生的问题同上,如果RDD中的数据量过多的话,还是可能会导致OOM内存溢出的异常。
- 如果纯内存的级别都无法使用,那么建议使用MEMORY_AND_DISK_SER策略,而不是MEMORY_AND_DISK策略。因为既然到了这一步,就说明RDD的数据量很大,内存无法完全放下。序列化后的数据比较少,可以节省内存和磁盘的空间开销。同时该策略会优先尽量尝试将数据缓存在内存中,内存缓存不下才会写入磁盘。
- 通常不建议使用DISK_ONLY和后缀为_2的级别:因为完全基于磁盘文件进行数据的读写,会导致性能急剧降低,有时还不如重新计算一次所有RDD。后缀为_2的级别,必须将所有数据都复制一份副本,并发送到其他节点上,数据复制以及网络传输会导致较大的性能开销,除非是要求作业的高可用性,否则不建议使用。
结束语
边栏推荐
- 一个普通人除了去工厂上班赚钱,还能干什么工作?
- L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
- 企业级日志分析系统ELK
- Leetcode-231-2的幂
- SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
- 星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
- Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
- Three. JS introductory learning notes 18: how to export JSON files with Blender
- Three. Introduction to JS learning notes 17: mouse control of 3D model rotation of JSON file
- Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
猜你喜欢
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
Xcode Revoke certificate
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
Notification uses full resolution
SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
torch. Numel action
torch.numel作用
Odoo integrated plausible embedded code monitoring platform
Three. JS introductory learning notes 18: how to export JSON files with Blender
随机推荐
torch.numel作用
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Numpy --- basic learning notes
MySQL数据库基本操作-DQL-基本查询
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
强化实时数据管理,英方软件助力医保平台安全建设
【HCSD大咖直播】亲授大厂面试秘诀-简要笔记
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
Migration and reprint
Odoo集成Plausible埋码监控平台
Introduction to pyGame games
PHP实现执行定时任务的几种思路详解
Vs tool word highlight with margin
Eye of depth (VI) -- inverse of matrix (attachment: some ideas of logistic model)
[hcsd celebrity live broadcast] teach the interview tips of big companies in person - brief notes
php 自带过滤和转义函数
分步式监控平台zabbix
Unity3d click events added to 3D objects in the scene
Three. JS introduction learning notes 12: the model moves along any trajectory line