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

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>
            午夜精品久久久| 欧美一区二区私人影院日本| 美国成人毛片| 久久躁狠狠躁夜夜爽| 在线精品一区二区| 亚洲激情一区| 欧美久久久久| 欧美一级久久| 久久久99精品免费观看不卡| 亚洲经典三级| 在线综合欧美| 激情欧美一区| 亚洲精品国产无天堂网2021| 欧美性生交xxxxx久久久| 久久国产一区| 免播放器亚洲| 亚洲欧美制服另类日韩| 久久久久久久999| 99riav1国产精品视频| 亚洲一区二区综合| 亚洲国产精品国自产拍av秋霞| 亚洲伦伦在线| 国精产品99永久一区一区| 亚洲电影视频在线| 国产精品视频一二| 欧美激情片在线观看| 国产精品久久久久久久久借妻| 久久久久久久成人| 欧美日韩在线三区| 免费成人av在线| 国产精品福利在线观看| 美国十次了思思久久精品导航| 欧美久久成人| 免费成人你懂的| 国产精品一区一区| 亚洲国产日韩欧美在线99| 国产午夜精品理论片a级探花| 亚洲国产一区二区三区在线播| 国产日本亚洲高清| 日韩一级片网址| 91久久精品国产| 久久aⅴ国产紧身牛仔裤| 亚洲网站在线观看| 欧美精品亚洲| 欧美成人性生活| 国产主播精品在线| 亚洲综合日韩在线| 亚洲综合精品一区二区| 欧美久久婷婷综合色| 欧美激情一区二区| 亚洲国产清纯| 久久久久久高潮国产精品视| 欧美在线观看视频在线| 欧美性一二三区| 夜夜狂射影院欧美极品| 9久草视频在线视频精品| 欧美成人精品h版在线观看| 猛干欧美女孩| 亚洲高清二区| 欧美.www| 亚洲欧洲一二三| 亚洲精品中文字| 欧美国产另类| 亚洲欧洲视频在线| 一区二区三区产品免费精品久久75| 久久亚洲精品伦理| 欧美激情一区三区| 艳妇臀荡乳欲伦亚洲一区| 欧美激情按摩| 亚洲免费久久| 亚洲欧美国产一区二区三区| 国产精品久久二区| 亚洲男人的天堂在线观看| 欧美一区二区三区免费观看 | 开元免费观看欧美电视剧网站| 国产精品v欧美精品v日韩 | 亚洲一区欧美| 久久精品久久综合| 在线观看视频欧美| 欧美激情中文字幕乱码免费| 亚洲麻豆国产自偷在线| 亚洲尤物在线视频观看| 国产精品视频导航| 久久精品电影| 亚洲国产精品va| 一区二区三区日韩精品| 国产精品拍天天在线| 久久精品国产免费| 亚洲成色www8888| 一区二区三区久久| 国产精品一区二区三区免费观看| 性娇小13――14欧美| 欧美成人免费全部| 亚洲尤物视频在线| 激情综合亚洲| 欧美三级在线视频| 久久激情五月婷婷| 亚洲乱码视频| 久久久久综合一区二区三区| 亚洲激情在线观看视频免费| 欧美性事免费在线观看| 久久一二三四| 亚洲一区国产视频| 亚洲高清视频中文字幕| 香蕉av777xxx色综合一区| 伊人久久av导航| 欧美天天视频| 欧美成人激情视频免费观看| 亚洲欧美日韩在线观看a三区| 亚洲电影免费| 久久久水蜜桃av免费网站| 亚洲视频 欧洲视频| 亚洲国产精品高清久久久| 国产精品视频一二三| 欧美激情亚洲激情| 久久精品国产999大香线蕉| 日韩一区二区福利| 欧美黄色免费网站| 久久九九精品| 午夜一区二区三区在线观看| 亚洲精品中文字幕女同| 一区视频在线| 国产欧美一区二区三区视频| 欧美精品在线视频| 毛片精品免费在线观看| 久久精品国产第一区二区三区最新章节| 亚洲精品日韩在线观看| 欧美gay视频| 久热这里只精品99re8久| 欧美一级二级三级蜜桃| 亚洲一区二区在线播放| 一二三四社区欧美黄| 亚洲日本黄色| 亚洲激情在线激情| 亚洲第一主播视频| 在线观看视频亚洲| 国内精品视频在线观看| 91久久夜色精品国产网站| 久久午夜电影网| 久久中文在线| 老司机久久99久久精品播放免费| 久久精品成人欧美大片古装| 欧美一区二区三区视频在线| 欧美一区二区啪啪| 欧美一区午夜精品| 欧美一区二区三区免费视频| 午夜精品一区二区三区在线| 午夜精品久久久久久久白皮肤| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 国产精品亚洲一区| 国产亚洲欧美日韩精品| 国产一区视频观看| 韩日在线一区| 亚洲国产专区校园欧美| 亚洲国产乱码最新视频| 亚洲精品乱码久久久久久| 亚洲美女av电影| 中国成人在线视频| 性欧美激情精品| 久久久久在线| 欧美国产日韩一区二区三区| 亚洲激情亚洲| 亚洲夜间福利| 久久精品国产久精国产爱| 蜜桃av噜噜一区| 欧美日韩直播| 国产性猛交xxxx免费看久久| 在线电影欧美日韩一区二区私密| 亚洲国内精品在线| 亚洲午夜激情网站| 久久久久久久久久看片| 亚洲经典自拍| 亚洲欧美在线一区| 美日韩精品免费观看视频| 欧美日韩一区二区精品| 国产一区二区三区高清播放| 亚洲激情在线激情| 午夜精品99久久免费| 欧美大秀在线观看| 一二三区精品| 开心色5月久久精品| 国产精品国产自产拍高清av王其| 国内精品亚洲| 亚洲深夜福利| 欧美+日本+国产+在线a∨观看| 亚洲精品日日夜夜| 久久夜色精品一区| 国产欧美精品一区二区色综合 | 西西裸体人体做爰大胆久久久 | 亚洲天堂av综合网| 免费试看一区| 亚洲一区不卡| 欧美精品九九| 亚洲成色777777在线观看影院| 亚洲一区二区精品在线| 欧美国产一区视频在线观看| 午夜精品久久久久久久99黑人| 欧美另类99xxxxx| 亚洲国产精品va在线观看黑人| 亚洲欧美一区在线|