昨天QQ群里提了一个Hadoop运行效率分配的问题,总结一下,写个文章。集群使用hadoop-1.0.3
有些hadoop集群在运行的时候,不完全是绝对平均的分配,不过需要尽可能平均的分配任务,避免某一台或者某几台服务器任务过重,其他服务器无事可做。这个,一方面是需要用到balancer,一个就是机架感知了。
通常,balancer是自动启动的。而机架感知则需要单独配置和编写脚本。不过,机架感知,不是说是感知哪个服务器坏了,是根据机架位置的拓扑结构来选取服务器进行任务的权重分配。
机架感知需要自己写一个脚本,然后放到hadoop的core-site.xml配置文件中,用namenode和jobtracker进行调用。
Python代码摘自竹叶青的博客
#!/usr/bin/python
#-*-coding:UTF-8 -*-
import sys
rack = {"hadoop-node-31":"rack1",
"hadoop-node-32":"rack1",
"hadoop-node-33":"rack1",
"hadoop-node-34":"rack1",
"hadoop-node-49":"rack2",
"hadoop-node-50":"rack2",
"hadoop-node-51":"rack2",
"hadoop-node-52":"rack2",
"hadoop-node-53":"rack2",
"hadoop-node-54":"rack2",
"192.168.1.31":"rack1",
"192.168.1.32":"rack1",
"192.168.1.33":"rack1",
"192.168.1.34":"rack1",
"192.168.1.49":"rack2",
"192.168.1.50":"rack2",
"192.168.1.51":"rack2",
"192.168.1.52":"rack2",
"192.168.1.53":"rack2",
"192.168.1.54":"rack2",
}
if __name__=="__main__":
print "/" + rack.get(sys.argv[1],"rack0")