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

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)  編輯 收藏 引用

    只有注冊用戶登錄后才能發(fā)表評論。
    網(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>
            先锋影音国产精品| 亚洲国产日韩一级| 久久久免费精品视频| 欧美久久电影| 久久久777| 亚洲影院色无极综合| 亚洲夜晚福利在线观看| 国产精品日韩欧美| 玉米视频成人免费看| 久久久www成人免费精品| 一本色道久久综合亚洲精品婷婷| 欧美精品电影| 亚洲激情在线| 亚洲人成毛片在线播放| 裸体女人亚洲精品一区| 欧美一区二区大片| 国精品一区二区| 久久久蜜桃精品| 久久久精品网| 91久久精品一区二区别| 欧美福利视频网站| 亚洲一区二区三区免费视频| 香蕉免费一区二区三区在线观看 | 欧美中文在线视频| 亚洲欧美成人网| 国产一区二区三区成人欧美日韩在线观看| 欧美在线一级视频| 久久精品国产久精国产一老狼| 激情六月婷婷久久| 亚洲激情成人网| 国产精品麻豆va在线播放| 欧美专区在线观看| 久久综合精品国产一区二区三区| 亚洲美女诱惑| 亚洲欧美一区二区三区极速播放| 亚洲视频中文| 国模吧视频一区| 亚洲第一色中文字幕| 欧美日韩成人一区二区| 欧美亚洲免费在线| 久久综合国产精品台湾中文娱乐网| 亚洲精品免费在线播放| 亚洲网站在线播放| 亚洲第一网站| 亚洲一区二区在线播放| 亚洲观看高清完整版在线观看| 久久久久久久久岛国免费| 欧美激情中文字幕一区二区| 亚洲国产黄色| 亚洲视频电影在线| 亚洲精品免费在线| 欧美激情中文字幕一区二区 | 国产一区二区三区久久| 美女诱惑一区| 欧美性大战久久久久| 鲁大师影院一区二区三区| 欧美日韩国产一区二区三区地区| 久久精品日产第一区二区三区| 欧美好吊妞视频| 久久久青草青青国产亚洲免观| 欧美激情在线观看| 久久中文字幕一区二区三区| 欧美日韩亚洲在线| 精品动漫一区| 一区二区电影免费在线观看| 欧美xxxx在线观看| 久久精品在线视频| 一区二区亚洲精品国产| 免费人成网站在线观看欧美高清| 久久午夜精品| 亚洲看片一区| 亚洲少妇在线| 国产亚洲亚洲| 欧美激情精品久久久久久变态| 欧美顶级少妇做爰| 亚洲伊人伊色伊影伊综合网| 亚洲欧美国产制服动漫| 国产一区二区毛片| 欧美日韩成人在线播放| 欧美日韩一区二区在线视频| 亚洲欧美日韩直播| 羞羞色国产精品| 亚洲一区亚洲二区| 狂野欧美性猛交xxxx巴西| 美玉足脚交一区二区三区图片| 亚洲精品欧美极品| 亚洲一区二区三区欧美| 黑人巨大精品欧美一区二区小视频| 免费在线欧美视频| 欧美三区视频| 久久亚洲美女| 欧美日韩一区二区在线观看视频| 久久久国产一区二区| 欧美成人伊人久久综合网| 亚洲淫片在线视频| 久久亚洲捆绑美女| 欧美日韩一级黄| 久久视频免费观看| 欧美日韩免费高清| 久久一区二区精品| 欧美视频一区二区三区在线观看 | 亚洲大胆女人| 欧美天天在线| 欧美成人一品| 国产精一区二区三区| 91久久在线| 欧美影片第一页| 一区二区日韩| 欧美一级片在线播放| 久久蜜桃精品| 91久久极品少妇xxxxⅹ软件| 欧美精品在线观看91| 亚洲电影下载| 午夜久久久久久| 亚洲永久精品大片| 欧美精品一区二区三区在线看午夜 | 欧美怡红院视频| 99视频精品全部免费在线| 久久精品91| 久久se精品一区二区| 欧美日韩在线播| 亚洲黄色影院| 免费成人av在线看| 久久久99免费视频| 国产精品你懂得| 在线午夜精品自拍| 中日韩男男gay无套| 欧美69wwwcom| 欧美大色视频| 亚洲人成毛片在线播放| 免费成人高清在线视频| 欧美成人小视频| 亚洲精品资源| 欧美精品v国产精品v日韩精品| 欧美jjzz| 亚洲精品乱码久久久久久日本蜜臀 | 亚洲精品无人区| 亚洲人成免费| 欧美高清视频| 亚洲人成网站在线播| 亚洲人体影院| 欧美精品一区在线发布| 亚洲美女av电影| 亚洲午夜一二三区视频| 欧美天天视频| 欧美影院成年免费版| 毛片av中文字幕一区二区| 在线视频观看日韩| 欧美+日本+国产+在线a∨观看| 亚洲国产精品一区二区尤物区| 亚洲精品中文字幕在线| 国产精品www.| 国产一区二区高清视频| 欧美日韩不卡在线| 99精品热6080yy久久| 欧美一二三区在线观看| 国内伊人久久久久久网站视频| 久久久国际精品| 最新日韩在线| 香蕉亚洲视频| 在线观看91精品国产麻豆| 欧美a级理论片| 一本高清dvd不卡在线观看| 欧美一区二区三区视频免费| 欧美一区二区三区在线观看| 狠狠操狠狠色综合网| 国产精品无码永久免费888| 欧美在线观看日本一区| 亚洲午夜影视影院在线观看| 99re66热这里只有精品3直播| 精品福利电影| 在线观看久久av| 久久久噜久噜久久综合| 亚洲区中文字幕| 久久精品亚洲一区二区三区浴池| 亚洲激情视频在线播放| 国产精品一区二区久久国产| 免费成人黄色片| 欧美高清影院| 亚洲国产成人久久综合一区| 欧美激情一区| 亚洲激情六月丁香| 亚洲裸体视频| 亚洲一二三四久久| 亚久久调教视频| 久久一区二区三区四区| 免费成人黄色片| 欧美日本韩国| 国产精品乱人伦一区二区| 国产免费观看久久黄| 国色天香一区二区| 乱中年女人伦av一区二区| 欧美成人激情在线| 欧美日韩不卡| 欧美刺激午夜性久久久久久久| 亚洲日本无吗高清不卡| 美女精品网站| 噜噜噜躁狠狠躁狠狠精品视频| 久久精品国产亚洲精品 | 亚洲手机视频|