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的更多相关文章

  1. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  2. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  3. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  4. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  5. 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 ...

  6. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  7. 《Cracking the Coding Interview》——第18章:难题——题目10

    2014-04-29 04:22 题目:给定一堆长度都相等的单词,和起点.终点两个单词,请从这堆单词中寻找一条变换路径,把起点词变成终点词,要求每次变换只能改一个字母. 解法:Leetcode中有Wo ...

  8. 《Cracking the Coding Interview》——第17章:普通题——题目10

    2014-04-28 23:54 题目:XML文件的冗余度很大,主要在于尖括号里的字段名.按照书上给定的方式进行压缩. 解法:这题我居然忘做了,只写了一句话的注解.用python能够相对方便地实现,因 ...

  9. 《Cracking the Coding Interview》——第13章:C和C++——题目10

    2014-04-25 20:47 题目:分配一个二维数组,尽量减少malloc和free的使用次数,要求能用a[i][j]的方式访问数据. 解法:有篇文章讲了六种new delete二维数组的方式,其 ...

随机推荐

  1. 4 - 函数&装饰器 and 迭代器&生成器

    函数是什么 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的.程序里函数的定义是: 定义:将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 ...

  2. hdu-2844&&POJ-1742 Coins---多重背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目大意: Tony想要买一个东西,他只有n中硬币每种硬币的面值为a[i]每种硬币的数量为c[ ...

  3. Linux高性能server编程——定时器

    版权声明:本文为博主原创文章.未经博主允许不得转载. https://blog.csdn.net/walkerkalr/article/details/36869913  定时器 服务器程序通常管 ...

  4. 优先队列(priority_queue)的cmp,POJ(2051)

    sort()函数的cmp为函数,priority_queue的cmp为类,具体写法是: struct Node { int i,j; } node[]; struct cmp { bool opera ...

  5. matlab的figure窗口命名为中文

    figure('NumberTitle', 'off', 'Name', '我的窗口名字');

  6. SQL随手记

    数据库改名 想要达到的效果,类似于将一个文件[复制粘贴重命名]. 0.首先得断开连接,复制一份备份.然后再连接上,进行下面的操作. 1.在树形上,选中要改名的数据库,右键重命名. 2.还是它,右键,属 ...

  7. war和war exploded的区别

    是选择war还是war exploded 这里首先看一下他们两个的区别: (1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布: (2)war exploded模式是直接 ...

  8. Java面试不得不知的问题(一)

    程序员面试   1. 面向对象的特征有哪些方面  ·   抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分, ...

  9. .NET向WebService传值为decimal、double、int、DateTime等非string类型属性时,服务器端接收不到数据的问题

    最近在做CRM项目时,使用C#调用SAP PI发布的WebService服务时遇到的问题: 向WebService传值为decimal.double.int.DateTime等非string类型数据时 ...

  10. mysql基础 反范式化