<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專(zhuān)題視頻專(zhuān)題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專(zhuān)題1關(guān)鍵字專(zhuān)題50關(guān)鍵字專(zhuān)題500關(guān)鍵字專(zhuān)題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專(zhuān)題關(guān)鍵字專(zhuān)題tag2tag3文章專(zhuān)題文章專(zhuān)題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專(zhuān)題3
        問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
        當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

        SchemaDesignforSocialInboxesinMongoDB

        來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-09 13:17:51
        文檔

        SchemaDesignforSocialInboxesinMongoDB

        SchemaDesignforSocialInboxesinMongoDB:Designing a schema is a critical part of any application. Like most databases, there are many options for modeling data in MongoDB, and it is important to incorporate the functional requirements and performance goals for your application w
        推薦度:
        導(dǎo)讀SchemaDesignforSocialInboxesinMongoDB:Designing a schema is a critical part of any application. Like most databases, there are many options for modeling data in MongoDB, and it is important to incorporate the functional requirements and performance goals for your application w

        Designing a schema is a critical part of any application. Like most databases, there are many options for modeling data in MongoDB, and it is important to incorporate the functional requirements and performance goals for your application w

        Designing a schema is a critical part of any application. Like most databases, there are many options for modeling data in MongoDB, and it is important to incorporate the functional requirements and performance goals for your application when determining the best design. In this post, we’ll explore three approaches for using MongoDB when creating social inboxes or message timelines.

        If you’re building a social network, like Twitter for example, you need to design a schema that is efficient for users viewing their inbox, as well as users sending messages to all their followers. The whole point of social media, after all, is that you can connect in real time.

        There are several design considerations for this kind of application:

      1. The application needs to support a potentially large volume of reads and writes.
      2. Reads and writes are not uniformly distributed across users. Some users post much more frequently than others, and some users have many, many more followers than others.
      3. The application must provide a user experience that is instantaneous.
      4. Edit 11/6: The application will have little to no user deletions of data (a follow up blog post will include information about user deletions and historical data)
      5. Because we are designing an application that needs to support a large volume of reads and writes we will be using a sharded collection for the messages. All three designs include the concept of “fan out,” which refers to distributing the work across the shards in parallel:

        1. Fan out on Read
        2. Fan out on Write
        3. Fan out on Write with Buckets

        Each approach presents trade-offs, and you should use the design that is best for your application’s requirements.

        The first design you might consider is called Fan Out on Read. When a user sends a message, it is simply saved to the inbox collection. When any user views their own inbox, the application queries for all messages that include the user as a recipient. The messages are returned in descending date order so that users can see the most recent messages.

        To implement this design, create a sharded collection called inbox, specifying the from field as the shard key, which represents the address sending the message. You can then add a compound index on the to field and the sent field. Once the document is saved into the inbox, the message is effectively sent to all the recipients. With this approach sending messages is very efficient.

        Viewing an inbox, on the other hand, is less efficient. When a user views their inbox the application issues a find command based on the to field, sorted by sent. Because the inbox collection uses from as its shard key, messages are grouped by sender across the shards. In MongoDB queries that are not based on the shard key will be routed to all shards. Therefore, each inbox view will be routed to all shards in the system. As the system scales and many users go to view their inbox, all queries will be routed to all shards. This design does not scale as well as each query being routed to a single shard.

        With the “Fan Out on Read” method, sending a message is very efficient, but viewing the inbox is less efficient.

        Fan out on Read is very efficient for sending messages, but less efficient for reading messages. If the majority of your application consists of users sending messages, but very few go to read what anyone sends them — let’s call it an anti-social app — then this design might work well. However, for most social apps there are more requests by users to view their inbox than there are to send messages.

        The Fan out on Write takes a different approach that is more optimized for viewing inboxes. This time, instead of sharding our inbox collection on the sender, we shard on the message recipient. In this way, when we go to view an inbox the queries can be routed to a single shard, which will scale very well. Our message document is the same, but now save a copy of the message for every recipient.

        With the “Fan Out on Write” method, viewing the inbox is efficient, but sending messages consumes more resources.

        In practice we might implement the saving of messages asynchronously. Imagine two celebrities quickly exchange messages at a high-profile event - the system could quickly be saturated with millions of writes. By saving a first copy of their message, then using a pool of background workers to write copies to all followers, we can ensure the two celebrities can exchange messages quickly, and that followers will soon have their own copies. Furthermore, we could maintain a last-viewed date on the user document to ensure they have accessed the system recently - zombie accounts probably shouldn’t get a copy of the message, and for users that haven’t accessed their account recently we could always resort to our first design - Fan out on Read - to repopulate their inbox. Subsequent requests would then be fast again.

        At this point we have improved the design for viewing inboxes by routing each inbox view to a single shard. However, each message in the user’s inbox will produce a random read operation. If each inbox view produces 50 random reads, then it only takes a relatively modest number of concurrent users to potentially saturate the disks. Fortunately we can take advantage of the document data model to further optimize this design to be even more efficient.

        Fan out on Write with Buckets refines the Fan Out on Write design by “bucketing” messages together into documents of 50 messages ordered by time. When a user views their inbox the request can be fulfilled by reading just a few documents of 50 messages each instead of performing many random reads. Because read time is dominated by seek time, reducing the number of seeks can provide a major performance improvement to the application. Another advantage to this approach is that there are fewer index entries.

        To implement this design we create two collections, an inbox collection and a user collection. The inbox collection uses two fields for the shard key, owner and sequence, which holds the owner’s user id and sequence number (i.e. the id of 50-message “bucket” documents in their inbox). The user collection contains simple user documents for tracking the total number of messages in their inbox. Since we will probably need to show the total number of messages for a user in a variety of places in our application, this is a nice place to maintain the count instead of calculating for each request. Our message document is the same as in the prior examples.

        To send a message we iterate through the list of recipients as we did in the Fan out on Write example, but we also take another step to increment the count of total messages in the inbox of the recipient, which is maintained on the user document. Once we know the count of messages, we know the “bucket” in which to add the latest message. As these messages reach the 50 item threshold, the sequence number increments and we begin to add messages to the next “bucket” document. The most recent messages will always be in the “bucket” document with the highest sequence number. Viewing the most recent 50 messages for a user’s inbox is at most two reads; viewing the most recent 100 messages is at most three reads.

        Normally a user’s entire inbox will exist on a single shard. However, it is possible that a few user inboxes could be spread across two shards. Because our application will probably page through a user’s inbox, it is still likely that every query for these few users will be routed to a single shard.

        Fan out on Write with Buckets is generally the most scalable approach of the these three designs for social inbox applications. Every design presents different trade-offs. In this case viewing a user’s inbox is very efficient, but writes are somewhat more complex, and more disk space is consumed. For many applications these are the right trade-offs to make.

        Schema design is one of the most important optimizations you can make for your application. We have a number of additional resources available on schema design if you are interested in learning more:

        Fan out on Read
        Fan out on Write
        Fan out on Write with Buckets
        Send Message Performance
        Best
        Single write
        Good
        Shard per recipient
        Multiple writes
        Worst
        Shard per recipient
        Appends (grows)
        Read Inbox Performance
        Worst
        Broadcast all shards
        Random reads
        Good
        Single shard
        Random reads
        Best
        Single shard
        Single read
        Data Size
        Best
        Message stored once
        Worst
        Copy per recipient
        Worst
        Copy per recipient


        Schema design is one of the most important optimizations you can make for your application. We have a number of additional resources available on schema design if you are interested in learning more:

      6. Check out the recording of our recent Schema Design webinar on this topic.
      7. Schema Design in general in the MongoDB Manual
      8. You can also view our schema design resources on the MongoDB docs page
      9. If you have any schema design questions, please view the archived questions on our user forum or ask a question yourselfon the MongoDB User Forum.
      10. 聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        SchemaDesignforSocialInboxesinMongoDB

        SchemaDesignforSocialInboxesinMongoDB:Designing a schema is a critical part of any application. Like most databases, there are many options for modeling data in MongoDB, and it is important to incorporate the functional requirements and performance goals for your application w
        推薦度:
        標(biāo)簽: in for design
        • 熱門(mén)焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門(mén)推薦

        專(zhuān)題
        Top
        主站蜘蛛池模板: 国产V片在线播放免费无码| 久久久久亚洲av无码专区导航| 亚洲一级Av无码毛片久久精品| 免费国产不卡午夜福在线| 国产男女猛烈无遮挡免费视频网站 | 亚洲Av永久无码精品黑人 | 亚洲成av人在线观看网站| 美女视频黄频a免费大全视频| 特级无码毛片免费视频| 怡红院免费全部视频在线视频| 99re这里有免费视频精品| 免费看国产精品3a黄的视频| 日韩成人在线免费视频| 亚洲精品无码AV中文字幕电影网站| 亚洲欧洲无码AV电影在线观看| 亚洲五月六月丁香激情| 国产成人精品日本亚洲18图| 老牛精品亚洲成av人片| 中文字幕无码免费久久9一区9 | 亚洲国产精品狼友中文久久久 | 亚洲综合久久1区2区3区| 亚洲色www永久网站| 一级特黄录像视频免费| 蜜桃成人无码区免费视频网站| 成年轻人网站色免费看| 亚洲伊人成无码综合网| 亚洲色图.com| 麻豆69堂免费视频| 无码人妻AV免费一区二区三区| 99久久免费精品国产72精品九九 | 国产美女精品久久久久久久免费 | 午夜毛片不卡免费观看视频| 亚洲一区二区精品视频| 亚洲国产精品日韩在线观看| 国产成人高清亚洲一区久久| 嫩草在线视频www免费观看| 免费网站看v片在线香蕉| 久久亚洲综合色一区二区三区 | 亚洲欧美成aⅴ人在线观看| 色www永久免费网站| 成人黄动漫画免费网站视频 |