MongoDB 性能 - 有多少数据库、集合? [英] MongoDB performances - how many databases, collections?

查看:54
本文介绍了MongoDB 性能 - 有多少数据库、集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 MongoDB 来存储时间序列数据.为了讨论起见,假设我部署了有限数量的传感器(例如 10-100-1000 个传感器).每个传感器都有十几个指标"(例如温度、湿度等),每分钟收集一次然后存储.然后有一个前端显示每个传感器的图表或按选定的时间间隔聚合.

I am looking to use MongoDB to store time-series data. For sake of discussion imagine I have a finite numbers of sensors deployed (e.g. 10-100-1000 sensors). Each sensors has a dozen of "metrics" (e.g. temp, humidity, etc) which are collected every minute and then stored. There is a front end which then displays charts for each sensors or aggregate on selected intervals.

在性能方面,存储它的最佳方法是什么?具体:

What is the best approach, performance wise, to store this? Specifically:

  • 在性能方面,我使用单个数据库还是多个数据库有关系吗?我可以创建 1db 用于每个传感器,或者只对所有内容使用单个巨大的 db.
  • 性能方面,如果我按每个分区对数据进行分区是否重要传感器或指标?
  • 性能方面,我应该为传感器制作一个集合吗信息然后收集数据或将两者合并收藏?

非常感谢

推荐答案

方法 1(A): 为所有内容创建单个数据库.(带单个收藏)

优点:

  • 减少维护:备份、创建数据库用户、恢复等

缺点:

  • You may see database level lock for creating indexes on large database
  • To perform operations on specific sensor data, you need to add additional indexes to fetch only sensor specific collection
  • You're bound to create not more than 64 indexes on a single collection. Although sounds bad indexing strategy.

方法 1(B): 为所有内容创建单个数据库.(每个传感器 1 个集合)

优点:

  • 减少维护:备份、创建数据库用户、恢复等
  • 最大限度地减少创建索引以从整个整体集合中识别传感器特定数据的需要
  • 每个特定于传感器的查询将仅针对特定集合.与单个大型集合相比,不需要将大型工作集拉入内存.
  • 在相对较小的集合上建立索引比在单个数据库中建立大集合更可行

缺点:

  • 您最终可能会创建过多的索引.(所有集合的索引总数之和).
  • 大量索引需要更多维护.
  • WiredTiger 在内部为集合创建 1 个文件,为索引创建 1 个文件.如果您的用例随着大量传感器的增长而增长.您最终可能会使用 64K 打开文件限制.

在性能方面,按每个传感器或指标对数据进行分区是否重要?

  • 这取决于您的分析应用预期的访问模式.

在性能方面,我应该先收集传感器信息然后收集数据还是将两者合并到同一个集合中?

  • 可能需要为传感器元数据和传感器数据创建一个集合.它将最大限度地减少在每个收集的传感器数据中重复传感器元数据.

  • Creating a collection for sensor metadata and sensor data may be needful. It will minimize duplicating sensor metadata in each and every collected sensor data.

您可能喜欢阅读威廉姆斯博客文章这里是关于设计这种模式的.

You may like to read Williams blog post here on designing this pattern.

与往常一样,最好设计一个示例架构并在您的测试环境中测试您的查询.

As always, it's better to design a sample schema and test your queries within your test environment.

这篇关于MongoDB 性能 - 有多少数据库、集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆