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

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>
            亚洲欧美日韩精品久久奇米色影视| 亚洲国产高清在线观看视频| 久久综合999| 一区二区激情小说| 免费国产自线拍一欧美视频| 亚洲一级二级| 亚洲天堂偷拍| 亚洲愉拍自拍另类高清精品| 日韩视频在线一区| 亚洲精品视频免费| 亚洲黑丝在线| 日韩一级大片| 一本色道久久精品| 亚洲一二三四区| 校园春色国产精品| 久久精品三级| 欧美a级片一区| 亚洲国产日韩一区| 99re66热这里只有精品3直播| 亚洲韩国精品一区| 亚洲午夜一区| 99re66热这里只有精品4 | 亚洲欧美高清| 久久久国际精品| 亚洲国产综合在线看不卡| 亚洲愉拍自拍另类高清精品| 午夜精品理论片| 久久夜色精品国产亚洲aⅴ| 欧美激情女人20p| 国产日韩欧美三级| 一区二区三区高清不卡| 久久全国免费视频| 亚洲男人影院| 欧美日韩国产va另类| 樱桃成人精品视频在线播放| 亚洲天天影视| 亚洲精品午夜| 蜜桃av一区| 精品69视频一区二区三区| 亚洲国产高清视频| 久久九九免费视频| 性刺激综合网| 国产日韩欧美一区| 亚洲精品乱码久久久久久日本蜜臀 | 亚洲二区在线观看| 亚洲欧美日韩一区| 日韩视频中文字幕| 欧美韩日一区二区三区| 亚洲黄色小视频| 国产精品无码永久免费888| 在线播放中文字幕一区| 男男成人高潮片免费网站| 亚洲电影在线看| 亚洲伊人一本大道中文字幕| 这里只有精品视频| 国产夜色精品一区二区av| 久久爱www| 免费在线亚洲| 亚洲一区在线直播| 亚洲欧美日韩国产| 亚洲大片免费看| 99在线精品视频在线观看| 国产精品美女久久久免费| 久久伊人免费视频| 欧美成年人网| 久久久久久久激情视频| 欧美精品在线观看91| 一区二区三区www| 国产精品久久久久久久久果冻传媒 | 欧美日韩不卡视频| 欧美日韩亚洲一区三区 | 久久av资源网| 欧美jjzz| 久久综合狠狠综合久久激情| 久久全国免费视频| 国产精品久久久久久久久婷婷| 久久久久久欧美| 国产精品你懂的在线欣赏| 欧美激情91| 亚洲欧洲一区二区三区在线观看| 午夜欧美不卡精品aaaaa| 亚洲综合精品| 国产精品区一区二区三区| 中文精品99久久国产香蕉| 亚洲免费观看高清完整版在线观看熊| 午夜一区在线| 另类专区欧美制服同性| 韩日欧美一区| 免费成人av资源网| 亚洲肉体裸体xxxx137| 91久久夜色精品国产网站| 欧美激情影音先锋| 亚洲精品一区二区在线| 亚洲欧美韩国| 一区二区三区我不卡| 久久午夜色播影院免费高清| 欧美风情在线| 亚洲欧美日韩中文播放| 欧美午夜视频网站| 久久精品论坛| 一区二区高清| 欧美99久久| 午夜亚洲性色福利视频| 亚洲高清在线精品| 国产精品xnxxcom| 久久久久久亚洲精品杨幂换脸 | 亚洲少妇诱惑| 在线欧美不卡| 国产日韩成人精品| 国产精品高潮呻吟久久| 免费亚洲电影在线| 午夜在线观看免费一区| 国产午夜精品久久久| 国产精品xxx在线观看www| 美女性感视频久久久| 午夜精品久久久久久久男人的天堂| 亚洲精品乱码久久久久久日本蜜臀| 久久国产手机看片| 欧美在线观看一区二区| 亚洲一区在线免费观看| 亚洲综合99| 欧美影院久久久| 久久精品免费播放| 久久xxxx精品视频| 久久精品国产一区二区三区免费看 | 欧美精品乱人伦久久久久久| 久久久久久久波多野高潮日日| 亚洲欧美成人在线| 午夜欧美电影在线观看| 亚洲欧美日韩精品在线| 亚洲网站在线观看| 午夜精品久久久久久久久久久久| 欧美一区=区| 欧美成人免费在线观看| 欧美日韩亚洲国产精品| 国产一区二区毛片| 一本一本大道香蕉久在线精品| 亚洲女爱视频在线| 欧美成人免费在线观看| 亚洲视频视频在线| 久久综合给合| 欧美性色视频在线| 91久久精品日日躁夜夜躁国产| 欧美精品国产一区二区| 国产日韩欧美自拍| 99精品视频免费在线观看| 欧美中文字幕在线| 欧美成人性生活| 亚洲欧美在线看| 欧美日韩国产影院| 午夜一区二区三区在线观看| 毛片av中文字幕一区二区| 国产日韩欧美在线| 欧美在线免费一级片| 91久久精品日日躁夜夜躁国产| 久久精品国产2020观看福利| 国产精品高潮视频| 亚洲免费小视频| 一本一道久久综合狠狠老精东影业 | 午夜在线不卡| 欧美精品一区二区在线播放| 久久蜜桃香蕉精品一区二区三区| 亚洲人线精品午夜| 欧美女同在线视频| 亚洲视频网站在线观看| 99日韩精品| 国产精品福利久久久| 午夜亚洲激情| 麻豆freexxxx性91精品| 亚洲精品视频在线| 最近看过的日韩成人| 欧美伦理a级免费电影| 一区二区三区日韩欧美| 亚洲一区二区三区四区五区午夜| 国产精品最新自拍| 免费看亚洲片| 欧美成人在线免费观看| 国产精品99久久久久久有的能看| 一区二区三区四区精品| 国产三级精品三级| 日韩一级片网址| 亚洲激情视频在线| 欧美在线视频免费播放| 亚洲网站视频| 老司机免费视频一区二区| 亚洲欧美日韩天堂| 欧美日韩成人一区| 欧美激情1区| 好吊视频一区二区三区四区| 狼人社综合社区| 欧美伦理91i| 久久久久www| 欧美三级视频在线观看| 免费欧美日韩国产三级电影| 国产精品日韩一区| 在线亚洲国产精品网站| 一本色道88久久加勒比精品| 久久综合色综合88| 欧美成人精品不卡视频在线观看 | 另类图片国产|