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. Python模块与函数

    python的程序由包(package).模块(module)和函数组成.模块是处理某一类问题的集合,模块由函数和类组成,包是由一系列模块组成的集合.包必须至少包含一个__init__.py文件,该文 ...

  2. TP5.1:模板赋值与变量输出

    模板赋值:assign() 模板渲染:fetch() 前提准备: 1.在app/index/controller下建立一个控制器,名为Templates.php,里面有test1和test2方法,并且 ...

  3. *1 Two Sum two pointers(hashmap one scan)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. Uva 10791 最小公倍数的最小和 唯一分解定理

    题目链接:https://vjudge.net/contest/156903#problem/C 题意:给一个数 n ,求至少 2个正整数,使得他们的最小公倍数为 n ,而且这些数之和最小. 分析: ...

  5. 数黑格有多少个,模拟题,POJ(1656)

    题目链接:http://poj.org/problem?id=1656 #include <stdio.h> #include <iostream> #include < ...

  6. Kruskal算法求最小生成树

    Kruskal算法是根据权来筛选节点,也是采用贪心算法. /// Kruskal ///初始化每个节点为独立的点,他的祖先为自己本身 void made(int n) { ; i<=n; i++ ...

  7. 2018.9.6 Java常考知识点总结

    一 Java中的值传递和引用传递(非常重要) 首先要明确的是:"对象传递(数组.类.接口)是引用传递,原始类型数据(整型.浮点型.字符型.布尔型)传递是值传递." 那么什么是值传递 ...

  8. R 语言爬虫 之 cnblog博文爬取

    Cnbolg Crawl a). 加载用到的R包 ##library packages needed in this case library(proto) library(gsubfn) ## Wa ...

  9. System.Web.UI.HtmlControls

    用来创建一个标签.HtmlContainerControl 一般用此类来新建标签. 可能我们熟悉System.Web.UI.WebControls;空间.System.Web.UI.WebContro ...

  10. 前端JavaScript之DOM使用案例

    1.弹出框点击关闭 (这个例子关键自己创建标签以及属性,不是太好想啊,而且作用相对来数也不是太大) <!DOCTYPE html> <html> <head> &l ...