青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

lxyfirst

C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
  33 Posts :: 3 Stories :: 27 Comments :: 0 Trackbacks


http://highscalability.com/numbers-everyone-should-know

Numbers Everyone Should Know

Google AppEngine Numbers

This group of numbers is from Brett Slatkin in Building Scalable Web Apps with Google App Engine.

Writes are expensive!

  • Datastore is transactional: writes require disk access
  • Disk access means disk seeks
  • Rule of thumb: 10ms for a disk seek
  • Simple math: 1s / 10ms = 100 seeks/sec maximum
  • Depends on:
    * The size and shape of your data
    * Doing work in batches (batch puts and gets)

    Reads are cheap!

  • Reads do not need to be transactional, just consistent
  • Data is read from disk once, then it's easily cached
  • All subsequent reads come straight from memory
  • Rule of thumb: 250usec for 1MB of data from memory
  • Simple math: 1s / 250usec = 4GB/sec maximum
    * For a 1MB entity, that's 4000 fetches/sec

    Numbers Miscellaneous

    This group of numbers is from a presentation Jeff Dean gave at a Engineering All-Hands Meeting at Google.

  • L1 cache reference 0.5 ns
  • Branch mispredict 5 ns
  • L2 cache reference 7 ns
  • Mutex lock/unlock 100 ns
  • Main memory reference 100 ns
  • Compress 1K bytes with Zippy 10,000 ns
  • Send 2K bytes over 1 Gbps network 20,000 ns
  • Read 1 MB sequentially from memory 250,000 ns
  • Round trip within same datacenter 500,000 ns
  • Disk seek 10,000,000 ns
  • Read 1 MB sequentially from network 10,000,000 ns
  • Read 1 MB sequentially from disk 30,000,000 ns
  • Send packet CA->Netherlands->CA 150,000,000 ns

    The Lessons

  • Writes are 40 times more expensive than reads.
  • Global shared data is expensive. This is a fundamental limitation of distributed systems. The lock contention in shared heavily written objects kills performance as transactions become serialized and slow.
  • Architect for scaling writes.
  • Optimize for low write contention.
  • Optimize wide. Make writes as parallel as you can.

    The Techniques

    Keep in mind these are from a Google AppEngine perspective, but the ideas are generally applicable.

    Sharded Counters

    We always seem to want to keep count of things. But BigTable doesn't keep a count of entities because it's a key-value store. It's very good at getting data by keys, it's not interested in how many you have. So the job of keeping counts is shifted to you.

    The naive counter implementation is to lock-read-increment-write. This is fine if there a low number of writes. But if there are frequent updates there's high contention. Given the the number of writes that can be made per second is so limited, a high write load serializes and slows down the whole process.

    The solution is to shard counters. This means:
  • Create N counters in parallel.
  • Pick a shard to increment transactionally at random for each item counted.
  • To get the real current count sum up all the sharded counters.
  • Contention is reduced by 1/N. Writes have been optimized because they have been spread over the different shards. A bottleneck around shared state has been removed.

    This approach seems counter-intuitive because we are used to a counter being a single incrementable variable. Reads are cheap so we replace having a single easily read counter with having to make multiple reads to recover the actual count. Frequently updated shared variables are expensive so we shard and parallelize those writes.

    With a centralized database letting the database be the source of sequence numbers is doable. But to scale writes you need to partition and once you partition it becomes difficult to keep any shared state like counters. You might argue that so common a feature should be provided by GAE and I would agree 100 percent, but it's the ideas that count (pun intended).
  • Paging Through Comments

    How can comments be stored such that they can be paged through
    in roughly the order they were entered?

    Under a high write load situation this is a surprisingly hard question to answer. Obviously what you want is just a counter. As a comment is made you get a sequence number and that's the order comments are displayed. But as we saw in the last section shared state like a single counter won't scale in high write environments.

    A sharded counter won't work in this situation either because summing the shared counters isn't transactional. There's no way to guarantee each comment will get back the sequence number it allocated so we could have duplicates.

    Searches in BigTable return data in alphabetical order. So what is needed for a key is something unique and alphabetical so when searching through comments you can go forward and backward using only keys.

    A lot of paging algorithms use counts. Give me records 1-20, 21-30, etc. SQL makes this easy, but it doesn't work for BigTable. BigTable knows how to get things by keys so you must make keys that return data in the proper order.

    In the grand old tradition of making unique keys we just keep appending stuff until it becomes unique. The suggested key for GAE is: time stamp + user ID + user comment ID.

    Ordering by date is obvious. The good thing is getting a time stamp is a local decision, it doesn't rely on writes and is scalable. The problem is timestamps are not unique, especially with a lot of users.

    So we can add the user name to the key to distinguish it from all other comments made at the same time. We already have the user name so this too is a cheap call.

    Theoretically even time stamps for a single user aren't sufficient. What we need then is a sequence number for each user's comments.

    And this is where the GAE solution turns into something totally unexpected. Our goal is to remove write contention so we want to parallelize writes. And we have a lot available storage so we don't have to worry about that.

    With these forces in mind, the idea is to create a counter per user. When a user adds a comment it's added to a user's comment list and a sequence number is allocated. Comments are added in a transactional context on a per user basis using Entity Groups. So each comment add is guaranteed to be unique because updates in an Entity Group are serialized.

    The resulting key is guaranteed unique and sorts properly in alphabetical order. When paging a query is made across entity groups using the ID index. The results will be in the correct order. Paging is a matter of getting the previous and next keys in the query for the current page. These keys can then be used to move through index.

    I certainly would have never thought of this approach. The idea of keeping per user comment indexes is out there. But it cleverly follows the rules of scaling in a distributed system. Writes and reads are done in parallel and that's the goal. Write contention is removed.

    posted on 2011-03-24 14:01 star 閱讀(431) 評論(0)  編輯 收藏 引用
    青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品v日韩精品v欧美精品网站| 亚洲电影观看| 亚洲午夜国产成人av电影男同| 欧美精品xxxxbbbb| 亚洲影视在线| 欧美亚洲日本网站| 国产在线视频欧美| 欧美成人精品影院| 亚洲国产精品ⅴa在线观看| 亚洲在线成人精品| 中文国产成人精品| 久久福利影视| 欧美一区亚洲| 亚洲黄色大片| 在线亚洲美日韩| 国产资源精品在线观看| 欧美激情精品久久久| 欧美日韩免费看| 久久国产综合精品| 欧美不卡视频一区| 性高湖久久久久久久久| 久久尤物电影视频在线观看| 在线视频欧美一区| 久久久久9999亚洲精品| 一区二区三区欧美激情| 性欧美超级视频| 日韩视频在线一区二区| 欧美a级一区| 久久久九九九九| 91久久嫩草影院一区二区| 欧美日韩亚洲一区三区 | 欧美日韩国产欧| 欧美在线观看一区| 欧美激情第三页| 久久久爽爽爽美女图片| 国产精品高潮视频| 亚洲人成网站999久久久综合| 国产一区二区三区在线观看免费视频| 亚洲激情成人| 亚洲国产黄色片| 欧美一区二区三区视频免费| 亚洲新中文字幕| 欧美激情亚洲精品| 久久精品91| 在线视频一区二区| 欧美日韩高清一区| 欧美国产日韩一区二区三区| 国产午夜精品理论片a级探花| 亚洲精品婷婷| 亚洲精品视频一区二区三区| 久热这里只精品99re8久| 欧美一区二区久久久| 欧美色视频在线| 日韩亚洲欧美一区二区三区| 亚洲欧洲偷拍精品| 欧美国产在线视频| 蜜桃av一区二区三区| 国产自产2019最新不卡| 亚洲淫片在线视频| 午夜性色一区二区三区免费视频| 欧美日韩亚洲系列| 一区二区三区产品免费精品久久75 | 欧美激情性爽国产精品17p| 国产一区高清视频| 久久精品视频免费观看| 久久久久久久高潮| 国产一区二区三区高清| 欧美一区观看| 久久中文字幕一区| 亚洲国产欧美不卡在线观看| 久久综合一区二区| 亚洲丶国产丶欧美一区二区三区| 91久久久在线| 欧美日韩一本到| 亚洲欧美一区二区三区在线| 久久狠狠一本精品综合网| 国产一区二区在线观看免费| 久久久蜜桃精品| 亚洲国产日本| 午夜精品福利电影| 国产在线视频欧美| 欧美成人午夜免费视在线看片| 亚洲国产成人高清精品| 99在线观看免费视频精品观看| 欧美午夜欧美| 欧美一区二区三区精品| 欧美国产欧美亚洲国产日韩mv天天看完整 | 欧美一区二区在线观看| 欧美第十八页| 亚洲天堂偷拍| 黄色工厂这里只有精品| 欧美成人资源| 亚洲欧美激情视频| 欧美成人精品激情在线观看| 中文一区二区在线观看| 黑人巨大精品欧美一区二区小视频| 蜜臀91精品一区二区三区| 99精品久久久| 久久免费99精品久久久久久| 日韩亚洲在线观看| 国产亚洲精品久久久久婷婷瑜伽| 欧美成人自拍| 欧美淫片网站| 一本色道久久综合狠狠躁篇怎么玩 | 亚洲一级网站| 亚洲国产精品一区制服丝袜 | 欧美日韩一区二区三区免费| 久久久久久久精| 夜夜爽夜夜爽精品视频| 免费久久精品视频| 午夜精品影院在线观看| 亚洲精品美女久久久久| 激情综合电影网| 久久精品国亚洲| aⅴ色国产欧美| 亚洲二区视频| 午夜精品美女自拍福到在线| 亚洲午夜91| 亚洲欧洲日本国产| 理论片一区二区在线| 亚洲一区二区三区午夜| 亚洲精品乱码久久久久| 国产中文一区二区| 国产精品免费小视频| 欧美日韩第一页| 欧美韩日一区| 欧美插天视频在线播放| 久久久久久久综合| 欧美一级成年大片在线观看| 一区二区三区高清在线| 亚洲欧洲日本一区二区三区| 欧美激情aⅴ一区二区三区| 久久综合伊人77777尤物| 久久久成人网| 久久久久久噜噜噜久久久精品 | 欧美精品日韩综合在线| 免费成人美女女| 久久美女性网| 久久永久免费| 免费成人高清视频| 久久午夜精品| 免费91麻豆精品国产自产在线观看| 久久久国产成人精品| 欧美一区视频在线| 欧美制服丝袜| 久久精品亚洲乱码伦伦中文| 久久福利电影| 蜜臀va亚洲va欧美va天堂| 久久伊人亚洲| 欧美另类在线观看| 欧美午夜精品久久久久免费视| 欧美三区在线视频| 国产精品免费网站| 国产自产女人91一区在线观看| 国产亚洲精品久久久| 影音先锋久久资源网| 91久久视频| 亚洲欧美一级二级三级| 欧美一区二区三区的| 久久蜜桃资源一区二区老牛 | 亚洲激情视频在线观看| 99精品欧美一区二区蜜桃免费| 一区二区高清视频在线观看| 亚洲欧美日韩在线一区| 久久理论片午夜琪琪电影网| 欧美成人午夜免费视在线看片 | 国产精品试看| 一区二区三区我不卡| 亚洲人成艺术| 亚洲欧洲av一区二区三区久久| 久久国产精品黑丝| 欧美大片在线观看| 在线视频亚洲欧美| 久久久精品性| 国产精品av免费在线观看| 国产一区二区三区四区老人| 亚洲七七久久综合桃花剧情介绍| 亚洲无限乱码一二三四麻| 久久久久国产精品麻豆ai换脸| 亚洲第一黄色网| 午夜精品偷拍| 欧美日韩成人| 亚洲福利专区| 小黄鸭精品密入口导航| 亚洲国产欧美国产综合一区| 亚洲欧美久久久久一区二区三区| 麻豆久久婷婷| 国产日韩亚洲| 亚洲午夜久久久久久久久电影网| 久久漫画官网| 久久蜜臀精品av| 国产精品亚洲精品| 亚洲免费不卡| 麻豆精品视频在线观看| 亚洲视频一区| 欧美特黄视频| 亚洲伦理网站| 亚洲高清在线精品| 久久精品夜色噜噜亚洲aⅴ | 久久久久综合一区二区三区|