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

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在线| 国产视频亚洲| 欧美精品亚洲| 狠狠色综合网| 久久久久免费视频| 亚洲风情亚aⅴ在线发布| 亚洲高清不卡av| 黄色欧美日韩| 午夜精品国产更新| 亚洲无限av看| 香蕉久久一区二区不卡无毒影院| 欧美视频在线观看视频极品| 怡红院精品视频在线观看极品| 欧美大片在线观看一区| 亚洲免费在线观看| 欧美激情综合色| 久久人人精品| 久久九九热re6这里有精品| 亚洲视频碰碰| 国产精品资源在线观看| 性欧美长视频| 中日韩在线视频| 亚洲裸体俱乐部裸体舞表演av| 久久综合久色欧美综合狠狠| 性色av一区二区三区| 亚洲图片你懂的| 亚洲一区二区欧美日韩| 在线国产日韩| 亚洲欧洲视频| 欧美黄污视频| 欧美成人国产一区二区| 久久亚洲不卡| 欧美亚洲一级| 亚洲黄色一区二区三区| 欧美大片18| 亚洲国产一区二区视频| 亚洲国产欧美一区二区三区丁香婷| 欧美在线不卡| 久久精品久久综合| 久久夜色精品亚洲噜噜国产mv| 久久久亚洲高清| 久热成人在线视频| 亚洲第一精品夜夜躁人人爽 | 免费观看成人网| 中日韩午夜理伦电影免费| 亚洲精品在线电影| 国产欧美日本| 欧美成人精品在线视频| 欧美中文在线视频| 国内精品免费在线观看| 亚洲精品在线二区| 亚洲砖区区免费| 亚洲第一天堂av| 一本色道久久88亚洲综合88| 国产亚洲欧美一区| 亚洲国产cao| 欧美日韩视频第一区| 亚洲国产一成人久久精品| 日韩天天综合| 亚洲日韩第九十九页| 亚洲综合国产| 欧美日韩视频在线| 美女视频一区免费观看| 国产麻豆午夜三级精品| 亚洲特黄一级片| 99re在线精品| 久久久综合视频| 久久综合伊人77777蜜臀| 一区二区三区在线视频免费观看| 亚洲欧美一区二区激情| 亚洲欧美偷拍卡通变态| 国产农村妇女精品| 最新高清无码专区| 亚洲高清视频的网址| 久久久久久**毛片大全| 久久夜色精品国产亚洲aⅴ| 国产精品久久77777| 99成人在线| 一区二区三区欧美亚洲| 欧美第十八页| 欧美国产高清| 亚洲第一精品夜夜躁人人躁| 亚洲一二区在线| 一区二区三区免费在线观看| 久久久精品视频成人| 亚洲欧美国产精品桃花| 欧美一级日韩一级| 亚洲精品一二区| 久久人人爽人人| 日韩亚洲精品视频| 国产一区二区三区奇米久涩| 亚洲人成网站在线播| 午夜精品视频| 91久久夜色精品国产九色| 欧美极品在线播放| 亚洲伦理在线免费看| 羞羞视频在线观看欧美| 欧美一区二区在线观看| 午夜电影亚洲| 在线观看91久久久久久| 欧美日本亚洲韩国国产| 一区二区三区国产| 午夜在线成人av| 国产资源精品在线观看| 欧美午夜电影网| 欧美高清视频一区| 免费久久99精品国产自在现线| 久久香蕉国产线看观看网| 午夜精彩国产免费不卡不顿大片| 亚洲国产视频一区二区| 久久成人资源| 亚洲国产小视频| 黄色一区二区在线观看| 国产麻豆精品久久一二三| 欧美精品一区在线发布| 久久综合网络一区二区| 欧美主播一区二区三区| 亚洲一区二区免费| 亚洲黄一区二区| 美国三级日本三级久久99| 香蕉成人啪国产精品视频综合网| 91久久黄色| 亚洲视频在线视频| 亚洲欧美日韩中文播放| 欧美**字幕| 亚洲欧美日韩国产| 欧美大片91| 永久域名在线精品| 一本色道久久综合| 亚洲在线成人精品| 久久亚洲春色中文字幕| 亚洲伊人第一页| 国产日本亚洲高清| 在线看无码的免费网站| 国产一区二区三区在线播放免费观看 | 亚洲欧美日韩国产精品| 亚洲欧美日韩在线| 久久免费午夜影院| 久久国产加勒比精品无码| 国产午夜精品理论片a级探花| 洋洋av久久久久久久一区| 午夜在线一区二区| 麻豆av一区二区三区久久| 亚洲国产另类精品专区| 亚洲性图久久| 欧美a级一区| 欧美偷拍另类| 黑人极品videos精品欧美裸| 先锋影音久久久| 亚洲国产日韩一区| 亚洲综合久久久久| 欧美片第1页综合| 一区在线视频观看| 亚洲欧美日韩精品久久亚洲区| 99综合在线| 国内精品一区二区三区| 亚洲少妇自拍| 亚洲精品看片| 午夜精品久久久久久久| 国产精品福利影院| 亚洲激情网址| 欧美成人黑人xx视频免费观看| 午夜精品久久99蜜桃的功能介绍| 国产拍揄自揄精品视频麻豆| 老司机一区二区三区| 亚洲精品国产拍免费91在线| 欧美日产国产成人免费图片| 亚洲一区二区三区成人在线视频精品| 亚洲最新视频在线播放| 欧美日韩国产成人在线观看| 亚洲一区国产一区| 久久国产日韩| 亚洲欧美中文字幕| 久久久久国产精品一区| 中文精品在线| 欧美a级片一区| 久久av一区二区三区亚洲| 久久一区二区三区国产精品| 久久婷婷成人综合色| 亚洲综合国产精品| 欧美华人在线视频| 女同一区二区| 国产午夜精品久久久久久久| 亚洲美女在线视频| 亚洲国产综合在线看不卡| 欧美一区二区三区播放老司机| 一区二区三区视频在线 | 久久精品人人| 国产精品免费久久久久久| 亚洲国产综合视频在线观看| 亚洲国语精品自产拍在线观看| 欧美影片第一页| 久久一综合视频| 亚洲精品激情|