1. 机器较多时, 编辑各个节点的/etc/hosts文件会很麻烦, 一般会架一个dns服务器进行解析.
2. 实现WritableComparable接口定义自己的写入方式时, 要注意hashCode()方法. 默认是使用Object.hashCode()这样的话, 会用对象的引用做为hashcode. Mapper会将相同key中hashCode()相同的聚在一起发送给Reducer.
比如Text的hashCode实现:
public class Text implements WritableComparable {
...
/** hash function */
public int hashCode() {
return WritableComparator.hashBytes(bytes, length);
}
...
}
这就是WordCount实例为什么相同的字符串为什么会通过Mapper聚在一起的原因了.
3. Mapper之后会根据key值排序, 使用实现WritableComparable接口的类的compareTo方法,或者注册一个Comparator.参考IntWritable的实现. Mapper不能根据value值排序, 这是mapreduce模型的规定. 所以要对value排序,只能把Mapper的结果inverse过来后,再根据key值排序. 即用InverseMapper与IdentityReducer.