Database Manual / Data Modeling / Designing Your Schema

Identify Application Workload确定应用程序工作负载

The first step in the schema design process is to identify the operations that your application runs most frequently. Knowing your application's most common queries helps you create effective indexes and minimize the number of calls the application makes to the database.模式设计过程的第一步是确定应用程序最频繁运行的操作。了解应用程序最常见的查询有助于您创建有效的索引,并最大限度地减少应用程序对数据库的调用次数。

About this Task关于此任务

When you consider your application's workload, consider the scenarios your application currently supports and scenarios it may support in the future. Design your schema to function in all stages of your application development.在考虑应用程序的工作负载时,请考虑应用程序当前支持的场景以及未来可能支持的场景。设计您的模式,使其在应用程序开发的所有阶段都能正常工作。

Steps步骤

1

Identify the data your application needs确定应用程序所需的数据

To identify the data that your application needs, consider the following factors:要确定应用程序所需的数据,请考虑以下因素:

  • Your application's users and the information they need.您的应用程序的用户及其所需的信息。
  • Your business domain.您的业务领域。
  • Application logs and frequently-run queries. To see database commands run on a MongoDB deployment, see Database Profiler.应用程序日志和频繁运行的查询。要查看在MongoDB部署上运行的数据库命令,请参阅数据库分析器

2

Create a workload table with your application's queries使用应用程序的查询创建工作负载表

Fill out the following table with the queries that your application needs to run:在下表中填写您的应用程序需要运行的查询:

Action动作Query Type查询类型Information信息Frequency频率Priority优先级
The action that a user takes to trigger the query.用户触发查询所采取的操作。The type of query (read or write).查询类型(读或写)。The document fields that are either written or returned by the query.由查询写入或返回的文档字段。How frequently your application runs the query.应用程序运行查询的频率。
Queries that are run frequently benefit from indexes and should be optimized to avoid lookup operations.频繁运行的查询受益于索引,应进行优化以避免查找操作。
How critical the query is to your application.查询对您的应用程序有多重要。

Example示例

The following example shows a workload table for a blog application:以下示例显示了博客应用程序的工作负载表:

Action动作Type类型Information信息Frequency频率Priority优先级
Submit a new article提交一篇新文章Writeauthor, text作者,文本10 per dayHigh
Submit a comment on an article对文章发表评论Writeuser, text用户,文本1,000 per day (100 per article)Medium
View an article查看文章Readarticle id, text, comments文章id、文本、评论1,000,000 per dayHigh
View article analytics查看文章分析Readarticle id, comments, clicks文章id、评论、点击10 per hourLow

Next Steps后续步骤

After you identify your application's workload, the next step in the schema design process is to map related data in your schema. See Map Schema Relationships.在确定应用程序的工作负载后,模式设计过程的下一步是映射模式中的相关数据。请参见映射模式关系