zoukankan      html  css  js  c++  java
  • 《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目1

    2014-04-24 00:38

    题目:加入你要设计一个服务,供至多1000个client查询每日股票的最高、最低、开盘、收盘价,请描述你要如何设计这个服务。

    解法:可以用SQL数据库组织,也可以用K-V数据库来提供更高性能。如果股票数量相对不大,还可以用XML文件组织数据。在百度里搜“BIDU”,或在Google里搜“GOOG”,就能看见例子了。

    代码:

     1 // 10.1 Suppose you're to design the backend part of a system, which provides queries of real-time stock prices. How would you do it?
     2 // Answer:
     3 //    Go and search "GOOG" on Google or Baidu, you'll get the real-time stock price of Google. The data transferring is best done with AJAX to the frontend, which can greatly save the amount of data transferred.
     4 //    As for the backend part, you have to use some techniques to store the data:
     5 //        1. SQL database, easy for various kinds of structured queries. You won't expose the direct SQL API to external users because it is not safe. Write a wrapper with the web programming language.
     6 //            Strength: Ability to provide more information than you expected.
     7 //            Weakness: Not so agile, if the data structure changes. Altering a SQL table is always expensive.
     8 //        2. XML files, a good way to store structured data. Good performance when the data scale is small or medium.
     9 //            Strength: Agile, easy to modify the schema. Regenerating the XML file is usually easy with script languages such as python.
    10 //            Weakness: Not suitable for large data scale, as you have to parse everything in the XML only to find an item inside.
    11 //        3. No-SQL database
    12 //            Strength: suitable for large scale, high concurrency, flexible with data schema changes.
    13 //            Weakness: Don't know yet, maybe more space usage.
    14 int main()
    15 {
    16     return 0;
    17 }
  • 相关阅读:
    Castle 开发系列文章
    ASP.NET MVC 3 Release Candidate 发布喽
    Scott Hanselman on SpeakerWiki
    2010年上半年计算机软考软件设计师试卷参考答案
    一站式示例代码库2010年11月5日更新
    从数据到代码—基于T4的代码生成方式
    CodeDOM
    老吉优秀的数据库访问层代码(转)
    非关语言: 设计模式
    EntLib
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3684417.html
Copyright © 2011-2022 走看看