摘要:
一致性Hash算法(转)2010-10-08 11:40:26|分类:分布式|字号订阅consistent hashing算法早在1997年就在论文Consistent hashing and random trees中被提出,目前在cache系统中应用越来越广泛;1基本场景比如你有N个cache服务器(后面简称cache),那么如何将一个对象object映射到N个cache上呢,你很可能会采用类似下面的通用方法计算object的hash值,然后均匀的映射到到N个cache;hash(object)%N一切都运行正常,再考虑如下的两种情况;1一个cache服务器m down掉了(在实际应用中必 阅读全文
摘要:
int swap2(int& x, int& y){ x = x + y; y = x - y; x = x - y;}这段代码相信大家都看过, 很多面试的人, 都喜欢拿出来做面试题。 和下面的标准swap比起来, 觉得有点高科技。int swap(int x, int y){ int w = x; x = y; y = w; }但其实经过性能测试, 前面在没有开 O2的情况下, 是明显输于后面的函数的。在开了O2的情况下, 差不多, 没有差异 阅读全文
摘要:
使用 ostringstream,很耗性能。原话是这么说的:t's really an implementation issue, butstd::localehas a static function that retrieves and set the 'global' locale. The global locale is defined to be used in several areas of the standard library which implies that there must be a global locale somewhere.In 阅读全文