Husky中文文档-C++ Husky Combiner 指南

Combiner

Combiner 基础

Husky中的combiner在消息发送出去之前进行聚合,从而降低消息量。当使用combiner时,来自同一台机器的拥有相同的key的所有信息将被聚合成一条消息。

不使用combiner的情况下发消息:

Husky::send_message(1, w, w_list);  // (Msg, Key, Obj_List)

使用combiner来发送消息:

Husky::send_message<Husky::SumCombine<int>>(1, w, w_list);  // (Msg, Key, Obj_List)

这样在同一台机器上对于同一个w的所有消息就会按照Husky::Sumcombine<int>提供的规则来组合。

例如,假设你在跑wordcount这个程序,并且hello,world,hello,husky放在同一台机器上。若不使用combiner, 那么四组(key, value)对都会被包装成消息通过网络发出去。若使用了combiner, 所有发送到同一个key的消息就会被聚集。以上的SumCombine<int>规定对key相同的消息进行叠加。在这种情况下,我们仅仅需要发送三条消息,即 ("hello",2), ("world",1), ("husky",1) (两条发送给'hello'的消息组合成为了一条).

大多数情况下,combiner可以极大程度地减少信息的发送量。但是,在选择是否使用combiner前,我们建议要进行多方面的考虑。

Combiner 细节

下面以Husky SumCombine的实现为例子:

template<typename MsgT>
struct SumCombine {
    static void combine(MsgT & val, MsgT const & inc) {
        val += inc;
    }
};

其他combiner的实现类似SumCombiner。

除了基于排序的普通combine外, Husky同时还支持了基于哈希的combine。当你需要使用基于哈希的combiner时,自定义的combiner类需要继承HashCombineBase。例如:

template<typename MsgT>
struct HashSumCombine : public HashCombineBase {
    static void combine(MsgT & val, MsgT const & inc) {
        val += inc;
    }
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值