设为首页 收藏本站
查看: 727|回复: 0

[经验分享] Hadoop的JVM重用

[复制链接]

尚未签到

发表于 2016-12-8 08:16:34 | 显示全部楼层 |阅读模式
Hadoop中有个参数是mapred.job.reuse.jvm.num.tasks,默认是1,表示一个JVM上最多可以顺序执行的task数目(属于同一个Job)是1。也就是说一个task启一个JVM。
   
比如我配的是每个slave节点最多同时运行8个map和8个reduce。那么在map阶段,slave节点会启动最多8个JVM用于map。如下:
 

root@slave1:~# jps
28291 Child
28290 Child
28281 Child
28293 Child
28277 Child
1487 DataNode
28298 Child
28273 Child
28272 Child
1636 TaskTracker
28799 Jps
root@slave1:~# ps -e |grep java
 1487 ?       00:53:26 java
TaskTracker
 1636 ?       00:12:42 java
DataNode
28272?        00:00:35 java
Child
28273?        00:00:35 java
Child
28277?        00:00:36 java
Child
28281?        00:00:36 java
Child
28290?        00:00:36 java
Child
28291?        00:00:37 java
Child
28293?        00:00:36 java
Child
28298?        00:00:36 java
Child

其中前两个是固定的进程。
 
为每个task启动一个新的JVM将耗时1秒左右,对于运行时间较长(比如1分钟以上)的job影响不大,但如果都是时间很短的task,那么频繁启停JVM会有开销。
 
如果我们想使用JVM重用技术来提高性能,那么可以将mapred.job.reuse.jvm.num.tasks设置成大于1的数。这表示属于同一job的顺序执行的task可以共享一个JVM,也就是说第二轮的map可以重用前一轮的JVM,而不是第一轮结束后关闭JVM,第二轮再启动新的JVM。
 
那么最多一个JVM能顺序执行多少个task才关闭呢?这个值就是mapred.job.reuse.jvm.num.tasks。如果设置成-1,那么只要是同一个job的task(无所谓多少个),都可以按顺序在一个JVM上连续执行。
 
如果task属于不同的job,那么JVM重用机制无效,不同job的task需要不同的JVM来运行。
 
注意:
JVM重用技术不是指同一Job的两个或两个以上的task可以同时运行于同一JVM上,而是排队按顺序执行。
一个tasktracker最多可以同时运行的task数目由mapred.tasktracker.map.tasks.maximummapred.tasktracker.reduce.tasks.maximum
决定,并且这两个参数在mapred-site.xml中设置。其他方法,如在JobClient端通过命令行
-Dmapred.tasktracker.map.tasks.maximum=number或者conf.set("mapred.tasktracker.map.tasks.maximum","number")设置都是无效的。
 
附《Hadoop权威指南》上的介绍:

Task JVM Reuse

Hadoop runs tasks in their own Java VirtualMachine to isolate them from other running tasks. The overhead of starting anew JVM for each task can take around a second, which for jobs that run for aminute or so is insignificant. However, jobs that have a large number of veryshort-lived tasks (these are usually map tasks), or that have lengthy initialization,can see performance gains when the JVM is reused for subsequent tasks.

 

With task JVM reuse enabled, tasks do not run concurrentlyin a single JVM. The JVM runs tasks sequentially. Tasktrackers can, however, runmore than one task at a time, but this is always done in separate JVMs. Theproperties for controlling the tasktrackers number of map task slots and reducetask slots are discussed in “Memory” on page 269.

The property for controlling task JVM reuseis mapred.job.reuse.jvm.num.tasks: it specifies the maximum number of tasks to run for a given job for eachJVM launched; the default is 1 (see Table 6-4). Tasks from different jobs are always run in separate JVMs. If theproperty is set to –1, there is no limit to the number of tasks from the same jobthat may share a JVM. The method setNumTasksToExecutePerJvm() on JobConfcan also be used to configure this property.

 
DSC0000.png
Tasks that are CPU-boundmay also benefit from task JVM reuse by taking advantage of runtimeoptimizations applied by the HotSpot JVM. After running for a while, the HotSpotJVM builds up enough information to detect performance-critical sections in thecode and dynamically translates the Java byte codes of these hot spots intonative machine code. This works well for long-running processes, but JVMs thatrun for seconds or a few minutes may not gain the full benefit of HotSpot. Inthese cases, it is worth enabling task JVM reuse.

 

Another place where ashared JVM is useful is for sharing state between the tasks of a job. Bystoring reference data in a static field, tasks get rapid access to the shareddata.

 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-311156-1-1.html 上篇帖子: hadoop的job执行流程 下篇帖子: hadoop几种排序简介
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表