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

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 閱讀(432) 評(píng)論(0)  編輯 收藏 引用

    只有注冊用戶登錄后才能發(fā)表評(píng)論。
    網(wǎng)站導(dǎo)航: 博客園   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>
            久久男人资源视频| 欧美国产精品久久| 亚洲手机视频| 国产精品露脸自拍| 欧美一区日韩一区| 久久九九久久九九| 亚洲国产片色| 亚洲国产精品日韩| 欧美日韩国产一级片| 亚洲视频在线视频| 午夜精品久久久久久久男人的天堂 | 99国产精品久久久久老师| 亚洲欧洲日韩在线| 国产精品实拍| 麻豆国产va免费精品高清在线| 久久一本综合频道| 一区二区av在线| 亚洲——在线| 在线国产欧美| 一本色道久久综合一区| 国产一区二区精品在线观看| 久久亚洲午夜电影| 欧美精品系列| 久久激情五月丁香伊人| 久久亚洲国产精品一区二区 | 欧美视频在线观看一区| 欧美在线黄色| 免费欧美在线视频| 性8sex亚洲区入口| 蜜臀久久久99精品久久久久久| 亚洲一区二区三区高清| 久久久久.com| 午夜激情综合网| 久久中文字幕一区| 亚洲欧美日韩精品一区二区| 久久久亚洲高清| 亚洲一区二区三区在线| 久久久亚洲国产美女国产盗摄| 一区二区三区日韩精品视频| 久久精品系列| 亚洲一区免费网站| 免费观看成人鲁鲁鲁鲁鲁视频| 香蕉成人伊视频在线观看| 欧美激情a∨在线视频播放| 久久精品成人欧美大片古装| 欧美日韩mv| 欧美激情成人在线视频| 国产欧美一区二区三区在线老狼| 亚洲国产一区在线观看| 影音先锋成人资源站| 午夜宅男欧美| 欧美一级免费视频| 欧美调教vk| 亚洲另类自拍| 亚洲三级影片| 蜜桃精品久久久久久久免费影院| 久久成人一区| 国产精品一区在线观看你懂的| 99国产精品久久久久久久成人热| 亚洲成人资源网| 久久精品主播| 久久夜色精品| 伊人久久大香线蕉综合热线 | 亚洲精品女人| 亚洲第一精品夜夜躁人人爽| 欧美在线观看一区| 久久成人精品无人区| 国产精品一区二区久激情瑜伽| 在线视频你懂得一区| 亚洲深夜福利在线| 欧美三级日韩三级国产三级| 亚洲精品资源美女情侣酒店| 亚洲精品一区二区三区不| 免费日韩av电影| 亚洲国产一区在线| 99xxxx成人网| 欧美视频中文字幕| 一级成人国产| 欧美一区二区三区久久精品| 国产视频欧美| 久久精品亚洲精品| 亚洲高清在线观看一区| 一本色道久久99精品综合| 欧美视频在线观看 亚洲欧| 中文在线资源观看网站视频免费不卡 | 欧美高清不卡在线| 亚洲另类在线视频| 校园激情久久| 国内偷自视频区视频综合| 久久视频一区二区| 亚洲啪啪91| 性欧美xxxx视频在线观看| 一区二区三区在线免费观看| 欧美+亚洲+精品+三区| 99re66热这里只有精品3直播| 亚洲欧美日本视频在线观看| 国产一区av在线| 女女同性女同一区二区三区91| 亚洲免费观看高清完整版在线观看| 亚洲在线视频网站| 伊人久久久大香线蕉综合直播 | 一本久久a久久免费精品不卡| 午夜精品在线| 亚洲国产网站| 国产欧美一区二区精品性色| 开心色5月久久精品| 亚洲天堂黄色| 欧美国产免费| 欧美在线啊v| 99re66热这里只有精品3直播| 国产精品日韩高清| 欧美国产另类| 久久国产精彩视频| 日韩视频一区二区三区在线播放免费观看 | 亚洲一区二区三区中文字幕在线| 国产一区二区三区在线观看免费| 久久午夜激情| 一区二区三区日韩精品| 欧美国产日韩a欧美在线观看| 香蕉久久精品日日躁夜夜躁| 亚洲毛片在线观看| 韩国美女久久| 国产乱码精品一区二区三| 免费成人性网站| 久久aⅴ乱码一区二区三区| 一区二区三区高清| 91久久在线播放| 麻豆国产va免费精品高清在线| 亚洲欧美国产视频| 亚洲色图综合久久| 日韩视频一区二区三区| 狠狠久久亚洲欧美专区| 国产精品综合视频| 国产精品久久久对白| 欧美日韩精品在线视频| 欧美成人情趣视频| 美女爽到呻吟久久久久| 久久久久久国产精品mv| 香蕉免费一区二区三区在线观看| 国产精品99久久久久久久久| 91久久精品国产91久久性色tv| 免费成人av| 欧美大片免费看| 欧美第一黄网免费网站| 欧美成年人视频网站| 免费成人黄色av| 蜜桃精品久久久久久久免费影院| 久久免费黄色| 免费日韩av| 亚洲电影免费观看高清完整版在线| 久久网站热最新地址| 久久综合久久综合久久综合| 久久综合伊人77777蜜臀| 老司机免费视频久久| 久久综合色88| 亚洲国产精品一区二区尤物区 | 免费日韩av片| 欧美成人亚洲| 亚洲国产精品一区二区www| 91久久精品久久国产性色也91| 亚洲国产第一页| 日韩午夜电影在线观看| 亚洲一区二区成人| 欧美亚洲免费| 老牛影视一区二区三区| 欧美激情久久久| 国产精品video| 国产日韩综合| 亚洲国产一区在线| 亚洲无线视频| 久久精品国产99国产精品澳门 | 亚洲一区二区三区中文字幕| 午夜精品99久久免费| 久久人91精品久久久久久不卡| 欧美国产视频一区二区| 一本色道**综合亚洲精品蜜桃冫| 亚洲免费一级电影| 美女脱光内衣内裤视频久久影院| 欧美欧美全黄| 国内精品嫩模av私拍在线观看 | 国内精品国语自产拍在线观看| 在线观看亚洲精品视频| 在线综合亚洲欧美在线视频| 欧美一区二区三区四区在线观看地址| 久久精品夜色噜噜亚洲a∨ | 亚洲欧美成人一区二区在线电影 | 欧美主播一区二区三区美女 久久精品人 | 亚洲毛片在线| 欧美一区二区三区在线观看| 欧美成人自拍视频| 亚洲在线视频免费观看| 欧美成人dvd在线视频| 国产日本欧美视频| 亚洲伦理一区| 男人的天堂亚洲| 亚洲欧美在线免费| 欧美日韩在线播| 亚洲国产精品一区二区久| 欧美中文字幕第一页| 亚洲欧洲美洲综合色网|