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

lxyfirst

C++博客 首頁 新隨筆 聯系 聚合 管理
  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 閱讀(436) 評論(0)  編輯 收藏 引用

    只有注冊用戶登錄后才能發表評論。
    網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


    青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲欧美日韩中文在线制服| 亚洲私人影院| 久热精品视频在线| 在线看一区二区| 欧美成人69av| 美女999久久久精品视频| 伊人成人开心激情综合网| 久热re这里精品视频在线6| 久久精品成人一区二区三区| 国内精品久久久久影院色| 久久蜜桃精品| 久久这里只有| 亚洲视频中文字幕| 亚洲在线免费| 狠狠色香婷婷久久亚洲精品| 六月丁香综合| 欧美日韩亚洲一区二区三区在线| 亚洲综合日本| 久久精品麻豆| 99在线视频精品| 午夜亚洲伦理| 亚洲激情视频在线播放| a4yy欧美一区二区三区| 国产日韩精品一区观看| 欧美高清免费| 国产精品xxxav免费视频| 久久久久九九九九| 欧美高清在线视频| 久久精品一区二区三区中文字幕| 久久精品国产99| 亚洲视频精选在线| 久久久久国产成人精品亚洲午夜| 99在线|亚洲一区二区| 午夜精品一区二区三区在线播放| 亚洲第一精品夜夜躁人人爽| 99视频精品| 亚洲国产天堂久久综合| 亚洲综合色丁香婷婷六月图片| 精久久久久久| 亚洲在线第一页| 一区二区动漫| 久久久亚洲人| 欧美一区二区久久久| 在线观看国产精品淫| 久久久激情视频| 亚洲欧洲在线播放| 欧美一级一区| 亚洲一区综合| 欧美极品在线播放| 欧美mv日韩mv国产网站| 国产视频久久| 亚洲中字在线| 亚洲伊人一本大道中文字幕| 欧美国产一区视频在线观看 | 久久爱www.| 午夜性色一区二区三区免费视频| 欧美韩国日本综合| 女女同性精品视频| 一色屋精品亚洲香蕉网站| 亚洲欧美日韩精品在线| 午夜精品成人在线视频| 欧美午夜激情在线| 夜夜精品视频一区二区| 亚洲美女免费视频| 母乳一区在线观看| 欧美高清视频在线| 永久久久久久| 久久久国产91| 久久亚洲一区二区| 韩国一区电影| 久久精品一区二区国产| 久久久久9999亚洲精品| 国产精品夜夜嗨| 亚洲自拍啪啪| 久久国产精品网站| 国模一区二区三区| 久久国产加勒比精品无码| 久久只精品国产| 亚洲黄色免费网站| 欧美电影在线播放| 99精品99久久久久久宅男| 一区二区高清视频在线观看| 欧美日韩午夜| 午夜精品av| 另类激情亚洲| 夜夜嗨av一区二区三区网站四季av| 欧美精品成人| 亚洲一区日韩| 另类酷文…触手系列精品集v1小说| 狠狠狠色丁香婷婷综合久久五月| 久久久一二三| 亚洲人成高清| 亚洲欧美日韩第一区| 国内精品久久国产| 欧美成人国产| 亚洲视频电影在线| 葵司免费一区二区三区四区五区| 91久久久亚洲精品| 欧美午夜精品久久久久久孕妇| 午夜精品福利在线观看| 欧美成人久久| 亚洲欧美日韩在线| 国产一区二区三区电影在线观看| 久久综合色播五月| 一区二区高清在线| 久久一区精品| 亚洲一区二区三区欧美| 红桃av永久久久| 欧美日韩亚洲高清| 久久久久网站| 亚洲一区二区四区| 亚洲激情在线播放| 久久久精品动漫| 在线综合欧美| 亚洲国产精品久久91精品| 欧美午夜免费电影| 蜜臀av一级做a爰片久久| 亚洲欧美日韩综合aⅴ视频| 亚洲电影第1页| 久久婷婷麻豆| 欧美亚洲系列| 一区二区激情视频| 亚洲福利专区| 国语自产精品视频在线看一大j8 | 久久精品国产第一区二区三区| 亚洲国产高清一区| 久久精品一二三区| 午夜精品999| 亚洲视频在线一区| 亚洲巨乳在线| 亚洲精品视频免费在线观看| 一区二区三区在线免费观看 | 蜜桃av噜噜一区| 午夜精品一区二区三区在线视| 99国产精品久久| 亚洲国产女人aaa毛片在线| 久久最新视频| 久久网站免费| 久久久免费精品| 久久xxxx精品视频| 欧美一区二区播放| 香港久久久电影| 亚洲午夜精品国产| 亚洲六月丁香色婷婷综合久久| 亚洲高清免费在线| 经典三级久久| 在线不卡欧美| 影音先锋中文字幕一区| 狠狠色综合一区二区| 狠狠色狠狠色综合人人| 今天的高清视频免费播放成人 | 狠狠色狠狠色综合| 国产一区二区三区四区老人| 国产精品一区二区久久国产| 国产精品丝袜久久久久久app| 欧美体内she精视频| 国产精品二区在线观看| 国产精品v日韩精品| 国产精品美女久久久久久久 | 久热精品在线视频| 老司机精品导航| 欧美成年人视频网站| 欧美大片免费观看| 欧美精品久久久久久| 欧美日韩在线播放| 国产乱码精品一区二区三区不卡 | 国产精品推荐精品| 国产亚洲一区二区三区在线播放| 国产亚洲制服色| 亚洲高清视频一区二区| 亚洲人成7777| 亚洲午夜日本在线观看| 欧美在线免费观看视频| 久久综合久久久久88| 91久久久久久国产精品| 9色国产精品| 欧美综合第一页| 欧美成人午夜影院| 国产精品户外野外| 黄色成人在线| 宅男噜噜噜66一区二区| 欧美中文字幕视频| 欧美激情一区二区三区蜜桃视频| 亚洲免费播放| 久久av资源网站| 欧美日韩国产黄| 国产婷婷成人久久av免费高清| 在线播放国产一区中文字幕剧情欧美 | 欧美激情一区二区三区在线视频观看| 亚洲精品国偷自产在线99热| 亚洲欧美综合一区| 免费日韩精品中文字幕视频在线| 欧美视频一区二区在线观看| 狠狠色丁香婷婷综合| 亚洲女性裸体视频| 亚洲大片免费看| 欧美综合国产| 国产精品一区二区久久| 日韩视频永久免费| 免费成人黄色|