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

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>
            亚洲高清在线视频| 日韩香蕉视频| 免费一级欧美在线大片| 麻豆av一区二区三区| 美女999久久久精品视频| 午夜国产精品视频| 久久激情五月婷婷| 欧美成人一品| 亚洲天堂成人| 欧美一区二区| 欧美精品久久一区二区| 国产欧美日韩精品丝袜高跟鞋| 激情伊人五月天久久综合| 麻豆精品视频在线| 国产精品无人区| 亚洲精品午夜精品| 欧美一区二区三区喷汁尤物| 欧美国产精品一区| 欧美激情亚洲视频| 中文精品在线| 樱桃成人精品视频在线播放| 亚洲一区久久久| 欧美电影免费观看高清完整版| 免费观看一区| 精品动漫一区| 亚洲精品国产精品国产自| 欧美一级成年大片在线观看| 亚洲国产精品v| 亚洲国产日韩在线一区模特| 香蕉亚洲视频| 国产精品视频久久一区| 久久久久久久国产| 亚洲视屏在线播放| 一区视频在线| 一区二区三区视频在线看| 欧美激情一区二区三区不卡| 性久久久久久久久| 亚洲人成在线观看| 欧美大片91| 国产精品女主播在线观看| 一区二区福利| 亚洲国产一区二区在线| 国产精品一区视频网站| 香蕉av福利精品导航| 老司机久久99久久精品播放免费| 国产一区二区三区在线免费观看| 久久九九国产精品| 欧美日韩亚洲系列| 亚洲性图久久| 亚洲欧美欧美一区二区三区| 国产欧美日韩三级| 日韩天天综合| 最近中文字幕mv在线一区二区三区四区| 亚洲午夜91| 一区二区三区你懂的| 麻豆成人在线| 老司机精品视频一区二区三区| 欧美视频手机在线| 欧美影片第一页| 欧美日韩亚洲三区| 亚洲精品美女在线观看播放| 极品少妇一区二区三区| 午夜精品婷婷| 欧美一区免费视频| 国产精品日韩久久久| 99热这里只有成人精品国产| 国产精品欧美日韩一区| 日韩午夜在线| 午夜精品视频在线| 欧美在线视频免费| 女同一区二区| 欧美日韩你懂的| 亚洲欧洲日本国产| 国产精品视频精品视频| 亚洲一区二区三区涩| 精品福利电影| 久久久精彩视频| 亚洲美女黄色| 性欧美暴力猛交另类hd| 国产精品久久亚洲7777| 亚洲校园激情| 性久久久久久| 国产一区二三区| 亚洲欧洲另类国产综合| 99re视频这里只有精品| 欧美日韩精品免费在线观看视频| 国产精品视区| 午夜精品电影| 亚洲免费黄色| 欧美午夜一区| 91久久黄色| 亚洲香蕉网站| 国产精品一二三| 久久9热精品视频| 午夜精品久久久久久99热| 国产欧美69| 久久免费国产| 久久久久看片| 国产三级精品三级| 亚洲视频在线一区观看| 久久精品人人做人人爽| 亚洲国产精品成人va在线观看| 欧美二区乱c少妇| 午夜在线精品| 影音先锋日韩有码| 欧美日本成人| 亚洲国产黄色| 亚洲黄一区二区三区| 久久国产精品色婷婷| 久久久久一区| 在线一区二区三区四区五区| 国产精品无码永久免费888| 六月天综合网| 午夜日韩在线观看| 欧美激情一区二区三区高清视频| 亚洲视频精选| 亚洲国产成人久久| 国产精品自拍一区| 免费在线一区二区| 香蕉成人久久| 日韩一区二区免费看| 美女日韩欧美| 欧美亚洲视频| 一本一本a久久| 欧美女激情福利| 久久精品视频在线看| 夜夜嗨av一区二区三区免费区| 狠狠入ady亚洲精品经典电影| 香蕉久久a毛片| 亚洲精品在线一区二区| 亚洲视频在线视频| 久久夜色精品一区| 性色av一区二区三区| 夜夜嗨av色综合久久久综合网| 欧美成人免费观看| 香蕉久久国产| 国产一区二区三区av电影| 欧美激情亚洲精品| 蘑菇福利视频一区播放| 久久福利一区| 欧美在线观看一区二区| 亚洲欧美在线x视频| 亚洲最新合集| 99国产精品久久久| 亚洲三级影院| 亚洲精品日韩在线观看| 亚洲国产日韩欧美| 亚洲高清免费视频| 亚洲第一黄色| 欧美国产一区二区| 欧美/亚洲一区| 欧美第一黄网免费网站| 男人插女人欧美| 欧美成人午夜激情视频| 欧美aaaaaaaa牛牛影院| 欧美不卡激情三级在线观看| 蜜臀av一级做a爰片久久| 麻豆91精品91久久久的内涵| 欧美波霸影院| 亚洲精品综合在线| 一区二区不卡在线视频 午夜欧美不卡'| 亚洲欧洲综合另类在线| 91久久综合| 一区二区三区日韩欧美| 亚洲视频成人| 欧美激情亚洲激情| 91久久香蕉国产日韩欧美9色| 亚洲国产精品专区久久| 亚洲精品资源美女情侣酒店| 亚洲视频在线一区| 久久精品国产免费观看| 美女福利精品视频| 欧美日韩免费| 国产区精品在线观看| 在线观看成人网| 一区二区高清在线观看| 亚洲欧美激情视频在线观看一区二区三区| 在线日韩av片| 狠狠入ady亚洲精品| 亚洲精品视频在线观看网站| 亚洲自拍偷拍福利| 久久影院午夜片一区| 欧美一区二区三区免费观看| 免费久久久一本精品久久区| 亚洲欧洲另类| 欧美一区二区在线观看| 欧美黄色aaaa| 国产亚洲精品福利| 亚洲欧洲另类| 欧美中文在线观看国产| 亚洲国产成人在线| 亚洲欧美激情一区二区| 欧美成人一品| 国产无遮挡一区二区三区毛片日本| 亚洲国产成人不卡| 欧美一区二区性| 亚洲精品视频免费在线观看| 欧美影视一区| 欧美视频一区二区三区在线观看| 好吊日精品视频|