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

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>
            亚洲精品一区二区在线| 一区二区三区www| 久久久精品2019中文字幕神马| 一区二区国产日产| 国产精品免费在线| 久久噜噜亚洲综合| 久久精品久久99精品久久| 在线观看不卡| 亚洲国产一区二区三区青草影视| 免费欧美电影| 亚洲一级黄色av| 香蕉av777xxx色综合一区| 国内成人精品2018免费看| 欧美国产综合视频| 欧美日韩亚洲一区二区三区四区| 亚洲欧美激情精品一区二区| 欧美一区二区三区四区在线| 亚洲电影观看| 99天天综合性| 激情久久中文字幕| 亚洲人线精品午夜| 国产一区二区三区高清在线观看| 亚洲国产第一| 国产伦精品一区二区三| 欧美电影在线观看完整版| 欧美日韩一二三区| 久久婷婷综合激情| 欧美日韩在线一区二区| 久久久久久久久伊人| 欧美日本精品一区二区三区| 欧美一区二视频在线免费观看| 蜜臀av国产精品久久久久| 亚洲午夜精品福利| 亚洲综合大片69999| 91久久久在线| 性欧美办公室18xxxxhd| 一本到12不卡视频在线dvd| 欧美中文字幕精品| 亚洲精品四区| 香蕉久久一区二区不卡无毒影院| 亚洲蜜桃精久久久久久久| 羞羞色国产精品| 亚洲美女在线视频| 久久亚洲视频| 久久精品亚洲一区二区| 国产精品久久99| 亚洲精品一区二| 亚洲激情视频在线| 久久激情五月激情| 久久精品91久久香蕉加勒比 | 久久成人精品| 欧美精品www在线观看| 久久综合久久综合这里只有精品 | 欧美日韩一区二区精品| 欧美不卡视频| 伊人久久婷婷| 久久久精品一区| 久久精品一区| 国产日韩欧美亚洲| 亚洲一区国产视频| 亚洲字幕一区二区| 国产精品久久久999| 一区二区三区久久| 在线视频日韩精品| 欧美日韩八区| 99国产精品久久| 亚洲婷婷综合色高清在线| 欧美日韩国产区一| 日韩午夜免费| 亚洲欧美中文在线视频| 欧美日本国产一区| 艳女tv在线观看国产一区| 亚洲一区二区成人| 欧美视频一区二区三区在线观看 | 亚洲欧美日韩精品在线| 欧美日韩精品一区视频| 日韩一区二区免费高清| 一区二区三区视频在线观看 | 欧美综合第一页| 久久亚洲国产成人| 在线精品高清中文字幕| 欧美成人免费全部观看天天性色| 亚洲国产精品va在线看黑人| 亚洲精品资源| 国产精品久在线观看| 亚洲男人的天堂在线| 久久国产福利| 亚洲电影中文字幕| 欧美另类极品videosbest最新版本| 91久久精品国产91久久性色tv| 99精品99| 国产日韩精品在线| 久热国产精品| 亚洲特级片在线| 久久中文精品| 亚洲天天影视| 伊人精品在线| 国产精品videosex极品| 久久国产精品99国产精| 亚洲激情二区| 久久gogo国模裸体人体| 亚洲欧洲精品成人久久奇米网| 欧美日韩另类丝袜其他| 欧美一区二区三区免费在线看| 欧美刺激午夜性久久久久久久| 在线午夜精品| 亚洲国产成人一区| 国产精品扒开腿做爽爽爽视频 | 欧美一区=区| 欧美黄色影院| 久久精品视频免费播放| 一区二区三区毛片| 樱桃国产成人精品视频| 欧美视频网址| 欧美a级在线| 亚洲欧美国产毛片在线| 亚洲精品免费看| 久久一区二区三区国产精品| 一本色道久久综合狠狠躁篇怎么玩 | 久久久999国产| 9色国产精品| 亚洲激情国产| 免费不卡欧美自拍视频| 欧美一区二区三区四区在线| 亚洲精品综合在线| 在线成人h网| 国产日韩欧美a| 国产精品嫩草影院一区二区| 欧美成人午夜77777| 久久久久国产一区二区| 亚洲欧洲av一区二区| 亚洲午夜在线观看视频在线| 亚洲精品九九| 亚洲第一区中文99精品| 老司机精品视频网站| 久久久91精品国产一区二区三区| 亚洲一级一区| 这里只有精品电影| 99视频一区| 99视频精品全部免费在线| 亚洲日本欧美在线| 亚洲日韩第九十九页| 亚洲国语精品自产拍在线观看| 国产一区二区三区四区老人| 国产精品主播| 国产午夜精品一区二区三区欧美| 国产精品美女久久久免费| 欧美性猛交视频| 国产精品高清在线| 国产精品日韩一区| 国产日韩欧美一区二区三区在线观看 | 亚洲免费观看| 99国产精品| 亚洲一区二区高清视频| 亚洲一区视频在线观看视频| 亚洲一区亚洲二区| 香蕉成人久久| 久久久久一区二区三区| 麻豆亚洲精品| 欧美激情一区二区三区蜜桃视频| 亚洲二区视频| 日韩一级网站| 亚洲宅男天堂在线观看无病毒| 亚洲一区二区三区精品视频 | 91久久精品视频| 99国内精品久久| 亚洲免费一区二区| 久久精品亚洲乱码伦伦中文| 老**午夜毛片一区二区三区| 欧美激情导航| 国产伦精品一区二区三区视频孕妇 | 欧美亚洲午夜视频在线观看| 久久激情五月激情| 欧美高清视频免费观看| 亚洲精品在线免费| 亚洲欧美日韩另类| 美女久久网站| 欧美四级在线观看| 国产综合久久| 日韩亚洲欧美精品| 性欧美8khd高清极品| 蘑菇福利视频一区播放| 亚洲精选一区| 欧美一区二区三区视频免费播放 | 性8sex亚洲区入口| 欧美精品二区| 狠狠色狠狠色综合人人| 99re6这里只有精品| 久久久久国产精品人| 亚洲日本成人女熟在线观看| 欧美一区网站| 欧美日韩亚洲三区| 在线观看一区二区视频| 亚洲欧美999| 亚洲国产精品热久久| 久久精品一区中文字幕| 国产精品国码视频| 99国产精品久久久久久久久久 | 一本色道久久综合亚洲精品不卡| 欧美一级网站|