腾讯在Spark上的应用与实践优化.pdf_第1页
腾讯在Spark上的应用与实践优化.pdf_第2页
腾讯在Spark上的应用与实践优化.pdf_第3页
腾讯在Spark上的应用与实践优化.pdf_第4页
腾讯在Spark上的应用与实践优化.pdf_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

腾讯在spark上的应用与实践优化 王联辉 agenda spark在腾讯的当前现状 spark在腾讯的典型应用及效果 腾讯在spark上的实践和优化 未来工作和计划 tdw(tencent distributed data warehouse) overview mapreduce spark hive/pig ide lhoste(workflow system) gaia(based on yarn) gaia集群结点数: 8000+ hdfs的存储空间: 150pb+ 每天新增数据: 1pb+ 每天仸务数: 1m+ 每天计算量: 10pb+ user defined jobs (scala/java/python/) hdfs storm docker ide: 用于提交sql戒脚本的eclipse插件和web界面 lhoste: 各类作业的工作流调度系统,类似于oozie gaia: 基于yarn进行定制和优化的资源管理系统 user 为什么我们引入spark? dag计算引擎 data cache & sharing 其他: task调度,数据广播等 m m m r r hdfs m m r hdfs m m r hdfs m m r m m m r r m m r r r hdfs iter.1 iter.2 iter.3 result1 result2 result3 hdfs iter.1 iter.2 iter.3 result1 result2 result3 spark在腾讯的当前现状 作业类型:etl,sparksql,machine learning,graph compute,streaming 每天仸务数:10k+ 部署模式:gaia(8000+ nodes,with 24 cores and 60g memory each) 底层存储: hdfs/hive/hbase/mysql/ 从2013年的spark 0.6版本开始,目前的版本是spark1.2 spark spark sql spark streaming mllib (machine learning) graphx scala/java/ python etl hdfs hive table hbase mysql postgresql others spark在腾讯的典型应用及效果 case 1: 预测用户的广告点击概率 case 2: 计算二个好友间的共同好友数 case 3: 用于etl的sparksql和dag任务 case 1: 预测用户的广告点击概率 gender age marital status location ad. one ad. two is click? man 20 unmarried newyork true false yes woman 40 married california false true yes man 60 married california false true no gende r age marital status location ad. one ad. two clicks possibility man 30 unmarried newyork true false ? man 30 unmarried newyork false true ? gender age marital status location ad. one ad. two clicks possibility man 30 unmarried newyork true false 30% man 30 unmarried newyork false true 50% w man woman ad. 1 ad.2 -0.896 0.895 -0.490 0.489 model train at spark table-1 table-2 table-3 table-4 实时预处理训练数据并推送到hdfs上 将训练数据(200g+) 导入至rdd & cache 初始化随机值给w并广播至各个executor 迭代训练60次左史 for (i p.x * (1 / (1 + exp(-p.y * (w.dot(p.x) - 1) * p.y .reduce(_ + _) w -= gradient 将模型推送广告后台在线服务器 每个计算的时间在1015分钟 hdfs driver executor cache task/rdd executor cache task/rdd task/rdd task/rdd task/rdd w w w = w-gradient gradient gradient data collect tools case 1: 预测用户的广告点击概率 user friend 2 1 4 1 1 2 5 3 6 3 6 5 5 6 3 6 user friend number of mutual friends 2 1 0 4 1 0 1 2 0 5 3 1 6 3 0 6 5 1 5 6 1 3 6 0 5亿用户数,500亿条边 10亿用户数,1000亿条边 user links table (id,fid) user friends table (id,fids) group by temp-1 table (id,fid,id-fids) join by temp table (id,fid,id-fids,fid-fids) join by result table (id,fid,count) case 2: 计算二个好友间的共同好友数 table-1 table-2 case 2: 计算二个好友间的共同好友数 user friend 2 1 4 1 1 2 5 3 6 3 6 5 5 6 3 6 pid id fid 1 2 1 1 2 2 3 6 3 4 1 5 3 6 3 4 6 5 5 6 val partitionstrategy = partitionstrategy.edgepartition2d table-1 table-2 pid id fid 1 2 1 1 2 2 3 6 3 4 1 5 3 6 3 4 6 5 5 6 id pid-list 1 1,3 2 1 3 2,3 4 3 5 3,4 6 2,3,4 pid uid-friendlist 1 1-2 2 - 1 2 3-6 6 -3,5 3 1-2 3 -6 4 -1 5 -3,6 6-3,5 4 5 -3,6 6 -3,5 id friend-list 1 2 2 1 3 6 4 1 5 3,6 6 3,5 id pid- list friend- list 1 1,3 2 2 1 1 3 2,3 6 4 3 1 5 3,4 3,6 6 2,3,4 3,5 join by id join by pid user friend total number of mutual friends 2 1 0 4 1 0 case 2: 计算二个好友间的共同好友数 table-1 table-2 table-3 table-4 table-5 table-6 edges/vertex nodes hive(map reduce) spark executors memory,cores/par titions 50b/0.5b 200 12 h 2 h 15g/1/5000 50b/0.5b 1000 - 43m 15g/1/5000 100b/1b 200 24 h 6h 25g/1/10000 100b/1b 1000 - 2h 25g/1/10000 one node, 55g memory,2*12t sata disk,24*1.9ghz cpu,1gbps network 根据shuffle的数据量来确定partition数 使用sort-based shuffle来提升性能和减少reduce的内存使用(spark-1.2). 在大集群时当连接超时后选择重试来减少executor丢失的概率(spark-1.2). 为避免executor被yarn给kill,通常需要设置 spark.yarn.executor.memoryoverhead. case 2: 计算二个好友间的共同好友数 case 3: 用于etl的sparksql和dag仸务 insert table test_result select t3.d ,count(*) from( select distinct a,b from join_1) t1 join ( select distinct b ,c from join_2) t2 on (t1.a = t2.c) join ( select distinct c ,d from join_3) t3 on (t2.b = t3.d) group by t3.d compute resources time hive 200 maps, 50 reduces(1 core, 3.2g memory) 30 min sparksql 50 executors(1 core, 4g memory) 5 min 腾讯在spark上的实践和优化 应用程序开发中的使用经验 对于etl作业使用劢态资源扩缩容特性 redcue阶段在map阶段未全部完成前执行 基于数据的大小预测stage的partition数 为sparksql的每个session分配一个driver count(distinct)的优化 基于排序的groupby/join 应用程序开发中的使用经验 当有小表时使用broadcast join代替common join 尽量使用reducebykey来代替groupbykey 设置spark.serializer=org.apache.spark.serializer.kryoserializer 根据shuffle的数据量来设置partition数,偏大些即可 大量的rdd在union时使用new unionrdd(sc, seq(rdd),防止 stackoverflowerror,而不是a.union(b).union(c) 使用yarn时设置spark.shuffle.service.enabled=true,减少shuffle数 据重做的代价 将akka的参数时间设长一些以及配置gc参数 对于etl作业使用劢态资源扩缩容特性 问题问题: 在此这前,spark仸务在task执行前通过指定参数来启劢固定数目的executor, 一旦达到用户指定值后保持住这个资源数,即使仸务运行过程中的task数增加戒 减少,也不会去改变executor的资源数目 executor task executor task sparkcontext task task job executorallocationmanager spark.dynamicallocation.enabled true spark.dynamicallocation.executoridletimeout 120 spark.dynamicallocation.schedulerbacklogtimeout 10 spark.dynamicallocation.minexecutors/maxexecutors redcue阶段在map阶段未全部完成前执行 executor-1 maptask-1 maptask-2 maptask-3 maptask-4 reducetask-1 reducetask-2 reducetask-3 reducetask-4 reducetask-5 time 1 time 2 time 3 问题问题:当申请固定的executors时且task数大于executor数,这时存在资源的空闲状态 executor-2 executor-3 executor-1 maptask-1 maptask-2 maptask-3 maptask-4 free free reducetask-1 reducetask-2 reducetask-3 executor-2 executor-3 reducetask-4 reducetask-5 time 4 当当executor没有没有map task需要执行时,即可在上面运行需要执行时,即可在上面运行reduce task并提前去拉并提前去拉 已完成的已完成的map数据。数据。 stage-1(task.size=parallelism) 基于数据的大小预测stage的partition数 怎么去设置spark.default.parallelism/spark.sql.shuffle.partitions? 输入数据每天在变化且有大量的历叱hivesql都没有设置partition数 maptask maptask maptask stage-0(task.size=blocks.size) reducetask reducetask reducetask reducetask reducetask reducetask maptask maptask maptask stage-0(task.size=blocks.size) reducetask reducetask reducetask reducetask reducetask reducetask stage-1(task.size=stage-0.input/256m) stage-2(task.size=stage-1.input/256m) stage-2(task.size=parallelism) 问题问题: 为sparksql的每个session分配一个driver yarn/applicationmaster querymaster spark driver sparksqlclient shell jdbc/odbc executor executor spark driver shell jdbc/odbc executor executor query-1 query-2 hive server query-1 query-2 hive server sparksqlclient sparksql hivecontext spark driver 问题问题: 一个hiveserver上所有的query都使用一个driver,导致query的内存和资源都会受 到单个driver的限制 sparksql hivecontext sqlpa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论