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

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>
            久久丁香综合五月国产三级网站| 欧美肥婆bbw| 欧美一区二视频在线免费观看| 另类图片国产| 中文亚洲视频在线| 欧美福利小视频| 在线观看国产欧美| 久久精品三级| 欧美一区2区三区4区公司二百| 国产精品国产三级国产aⅴ浪潮 | 国产日韩欧美综合在线| 一区二区日本视频| 亚洲国产天堂网精品网站| 亚洲欧美成人综合| 国产模特精品视频久久久久 | 亚洲在线观看视频| 欧美吻胸吃奶大尺度电影| 一区二区高清在线| 亚洲视频一区二区免费在线观看| 欧美久久久久久久久| 99国产精品久久久久久久成人热| 欧美电影免费观看高清| 久久久免费精品| 亚洲国产欧美不卡在线观看| 欧美激情综合色| 欧美另类videos死尸| 日韩一级成人av| 亚洲午夜小视频| 国产一区在线视频| 欧美成人精品在线| 欧美日韩视频免费播放| 午夜精品短视频| 欧美一区午夜视频在线观看| 尤物九九久久国产精品的特点 | 亚洲天堂免费观看| 在线一区二区三区四区| 国产日韩欧美中文| 欧美国产综合视频| 亚洲国产精品毛片| 欧美精品一区二区三区很污很色的| 一本久道久久综合婷婷鲸鱼| 一区二区三区免费观看| 国产有码在线一区二区视频| 欧美激情一区二区三区全黄| 国产精品hd| 欧美成人自拍| 国产精品三级视频| 欧美激情aⅴ一区二区三区| 国产精品久久久久永久免费观看| 久久亚洲精品伦理| 国产精品sss| 欧美激情精品久久久久久久变态 | 欧美va亚洲va日韩∨a综合色| 亚洲免费成人av电影| 亚洲免费小视频| 最新亚洲一区| 亚洲欧美日韩精品久久| 亚洲老板91色精品久久| 亚洲性xxxx| 亚洲精品黄色| 久久国产一二区| 亚洲性夜色噜噜噜7777| 久久精品国产99| 亚洲无毛电影| 欧美精品午夜| 欧美国产一区视频在线观看| 国产亚洲欧美色| 99国产精品| 91久久国产综合久久蜜月精品 | 在线免费观看日本欧美| 亚洲欧美经典视频| 亚洲一区二区三区精品视频| 久久综合久久综合久久综合| 欧美一区二区视频97| 欧美日韩在线播| 亚洲激情视频在线观看| 激情丁香综合| 欧美一级播放| 久久成人精品无人区| 欧美视频精品在线| 亚洲激情成人| 亚洲六月丁香色婷婷综合久久| 久久亚洲一区二区三区四区| 久久精品一级爱片| 国产欧美日韩综合一区在线观看 | 久久全球大尺度高清视频| 久久激情视频| 国产日韩一区二区三区| 亚洲制服欧美中文字幕中文字幕| 正在播放欧美视频| 欧美日韩另类一区| 亚洲免费av观看| 亚洲精选大片| 欧美日韩国产三级| 亚洲免费成人av| 亚洲视频精品在线| 国产精品成人v| 亚洲一区二区av电影| 亚洲欧美视频在线| 久久成人亚洲| 美女任你摸久久| 亚洲国产欧美一区| 欧美不卡在线| 亚洲第一在线综合在线| 91久久综合| 欧美日韩国产成人在线| 在线亚洲高清视频| 久久精品久久综合| 精品成人一区二区| 欧美96在线丨欧| 99re6这里只有精品| 亚洲一区二区欧美日韩| 国产精品国码视频| 亚洲欧美日韩在线| 牛牛国产精品| 日韩视频免费| 国产精品视频成人| 久久九九免费| 亚洲精品孕妇| 翔田千里一区二区| 怡红院精品视频| 欧美日韩成人一区二区| 午夜精彩视频在线观看不卡 | 亚洲欧美自拍偷拍| 欧美成人免费在线| 亚洲天堂免费在线观看视频| 国产精品高精视频免费| 久久成人av少妇免费| 亚洲国产精品精华液网站| 亚洲一区二区在线播放| 国产欧美在线观看| 欧美精品成人在线| 性欧美video另类hd性玩具| 欧美激情一区二区三区全黄 | 狂野欧美性猛交xxxx巴西| 亚洲日本久久| 国产情人综合久久777777| 欧美福利视频在线观看| 亚洲一区国产| 亚洲黄色成人久久久| 久久精品99久久香蕉国产色戒| 亚洲三级网站| 国产性做久久久久久| 欧美日韩一区二区三区四区在线观看 | 国产精品国产福利国产秒拍| 久久久精品国产免大香伊| 亚洲最新在线| 亚洲高清免费视频| 噜噜噜噜噜久久久久久91| 亚洲一二三四区| 亚洲精品视频免费在线观看| 国产一区二区三区在线观看精品| 欧美日韩妖精视频| 欧美成人黑人xx视频免费观看| 羞羞答答国产精品www一本| 亚洲激情视频在线播放| 欧美xart系列高清| 久久人91精品久久久久久不卡| 小黄鸭精品密入口导航| 亚洲视频观看| 99在线热播精品免费99热| 亚洲国产精品激情在线观看| 久久久久在线| 亚洲欧美日韩专区| 在线一区日本视频| 亚洲韩日在线| 亚洲国产一区二区精品专区| 免费观看欧美在线视频的网站| 久久久久久久久蜜桃| 亚洲欧美日本视频在线观看| 99视频精品在线| 亚洲精品乱码久久久久久黑人 | 国产精品igao视频网网址不卡日韩| 欧美黄色日本| 欧美激情按摩| 欧美极品影院| 欧美成在线视频| 欧美高清视频一区| 欧美激情第8页| 欧美噜噜久久久xxx| 欧美精品www| 欧美日韩一区二区三区四区五区| 欧美日韩国产免费| 欧美午夜精品理论片a级按摩| 欧美天天综合网| 国产精品露脸自拍| 国产精品视频yy9299一区| 国产手机视频一区二区| 精品福利电影| 亚洲美女黄网| 亚洲天堂av图片| 久久精品视频免费观看| 久久综合九色99| 亚洲激情综合| 一区二区高清视频| 午夜精品久久久久久久99黑人| 欧美在线视频在线播放完整版免费观看 | 欧美中文在线字幕| 久久久噜噜噜久久| 欧美aⅴ一区二区三区视频|