《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目7
2014-04-24 22:06
题目:搜索引擎问题,如果有一列100台服务器的集群,用来响应查询请求,你要如何设计query分发和cache策略?
解法:query分发可以用计算数字签名并对机器数取模来确定分发到的目标机器。当然这个和hash一样,会存在冲突和故障的情况,需要额外处理。至于cache策略,基本思想是LRU,对于数据变更,采取另加工作线程来定期更新,遇到特定事件也可以主动更新。cache的作用不只是加速查询,特定情况下也可以容灾,所以得根据情况分层设计。
代码:
// 10.7 You have a search engine, the main backend has a cluster of 100 machines. If the processSearch(string query) method is the main procedure to handle the search. How would you design the caching strategy?
// Answer:
// Load balancing:
// 1. Keep strict watch on CPU, IO and memory usage. If occupation is too heavy, start forwarding the incoming requests to its next neighbors.
// 2. Cache may be multi-level, secondary level cache may be used to enlarge cache results, saving the energy of doing new searches.
// 3. If the hit rate of cache is getting abnormally low, force the cache to clear up. These things do happen when some kind of popular events occur. People will flood in to search about some event, and the old results in cache is no longer useful.
// For example, if the debris of aircraft MH370 is found, there will be awfully lot of searches about it within one miniute. The cache has to be refreshed.
// Caching:
// 1. Every string is computed as digital sum, which is an unsigned integer.
// 2. The integer is modulo by num_of_machine in the cluster to get a remainder, this query is usually processed by machine[remainder].
// 3. The cache on machine[remainder] most likely will have ready result for the query.
// 4. If the machine is too busy, however, it will forward the request to its next alive neighbor.
// After all, none of the strategies come out of nowhere, it must be drawn from observation, and verified with real experiments.
int main()
{
return ;
}
《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目7的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- 《Cracking the Coding Interview》——第18章:难题——题目10
2014-04-29 04:22 题目:给定一堆长度都相等的单词,和起点.终点两个单词,请从这堆单词中寻找一条变换路径,把起点词变成终点词,要求每次变换只能改一个字母. 解法:Leetcode中有Wo ...
- 《Cracking the Coding Interview》——第17章:普通题——题目10
2014-04-28 23:54 题目:XML文件的冗余度很大,主要在于尖括号里的字段名.按照书上给定的方式进行压缩. 解法:这题我居然忘做了,只写了一句话的注解.用python能够相对方便地实现,因 ...
- 《Cracking the Coding Interview》——第13章:C和C++——题目10
2014-04-25 20:47 题目:分配一个二维数组,尽量减少malloc和free的使用次数,要求能用a[i][j]的方式访问数据. 解法:有篇文章讲了六种new delete二维数组的方式,其 ...
随机推荐
- jmeter参数化读取数据进行多次运行
jmeter参数化数据,可以使用csv,还可以使用数据库的方式 1.使用csv读取数据 在线程组中,配置原件中,选择csv data set config 1.本地创建了16个数据,存为test.tx ...
- swift 注解 (和java比照)@attribute name
Attributes provide more information about a declaration or type. There are two kinds of attributes i ...
- 立体最短路径,广搜(POJ2251)
题目链接:http://poj.org/problem?id=2251 参考了一下大神们的解法.也有用深搜的.然而,之前不久看到一句话,最短路径——BFS. 参考:http://blog.csdn.n ...
- 种类并查集,TOJ(1706)
题目链接:http://acm.tju.edu.cn/toj/showp1706.html 很类似Poj的一道帮派的问题,记得找到的可疑的关系,不要将集合刷新就可以了. 1706. A Bug's ...
- Android检查更新(是否强制更新)
Android应用客户端通常会需要更新,而且根据需求分为普通更新和强制更新.是否强制更新可通过检查更新时从服务器获取的标志位来判断. public class UpdateManager { priv ...
- 剑指offer39 平衡二叉树
剑指上用了指针传递,这里用的引用传递 class Solution { public: bool IsBalanced_Solution(TreeNode* pRoot) { ; return IsB ...
- 如何在Linux中显示和设置主机名
原文链接 随着连接到网络的计算机数量越来越多,每一台计算机都需要有一个属性来区别于其它计算机.和现实世界中的人一样,计算机也有一个叫做hostname(主机名)的属性. 什么是hostname 从它的 ...
- angularJS 提示
1.通常angularJS应用程序将模块和控制器包含在JavaScript文件中. 2.在模块的定义中[]参数是用来表示模块的依赖关系. 3.中括号[]为空,表示该模块没有依赖关系,如果有依赖关系的话 ...
- data-ng-init 指令
1.data-ng-init指令为AngularJS应用程序定义了一个初始值. 2.通常情况下,data-ng-init指令并不常用,将会使用控制器或模块来代替它.
- C# unchecked运算符
一.C# unchecked运算符 unchecked运算符用于取消整型算术运算和转换的溢出检查. 二.提示 默认情况下,都是unchecked选项.因此,只有在需要把几个未检查的代码行放在一个明确标 ...