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 }
  • 相关阅读:
    synchronized优化手段:锁膨胀、锁消除、锁粗化和自适应自旋锁...
    synchronized 优化手段之锁膨胀机制!
    synchronized 加锁 this 和 class 的区别!
    SpringBoot中时间格式化的5种方法!
    阿里云ddns shell 脚本
    adb 备份apk
    paddlex_gui_win10(飞浆)
    cuda 版本对照
    PaddleHub
    yum 查找库对应的包
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3684417.html
Copyright © 2011-2022 走看看