在生产中使用 MongoDB 构建索引的时间和频率
我即将使用 MongoDB 作为存储来部署一个 Web 应用程序。问题是,我可以在本地随时构建索引(也可以自动完成) - 但你不应该在生产中这样做。现在切换到生产,我不太确定何时构建索引以及多久构建一次。我应该每天都这样做吗?我应该每周做一次吗?我的项目就像一个小型社交网络 - 假设有一天我将拥有大约 100,000 个用户。根据数据量的不同,构建索引可能需要数小时甚至数天的时间。
我打算在后台构建索引(请参阅此处 http:// /www.mongodb.org/display/DOCS/Indexing+as+a+Background+Operation)。它仍然会导致写锁定,但构建作业将暂停以允许其他读取器和写入器访问数据库 - 因此,如果数据库负载很重,后台索引构建仍然会对性能产生负面影响方式。因此,应该在流量最小的时间窗口内完成(在此处进行研究http://www.javabeat.net/articles/353-indexing-in-practice-using-mongodb-1.html)。
有人有关于何时以及多久在生产中创建索引(最好是有大量数据)的经验吗?我正在使用 Rails 和 Mongoid (http://mongoid.org/)。
I am about to deploy a web app using MongoDB as storage. The problem is, that locally I can build the indexes whenever I want (also done automatically) - but you shouldn't do that in production. Now switching to production I am not quite sure on when to build the indexes and how often. Should I do it every day? Should I do it once a week? My project is like a small social network - so let's say I will have about 100.000 users someday. Depending on the amount of data it could take hours or even days to build indexes.
I intend to build my indexes in the background (see here http://www.mongodb.org/display/DOCS/Indexing+as+a+Background+Operation). It will still cause a write lock, but the build job will pause to allow other readers and writers to access the database - so if I there would be a heavy load on the database, a background index build would still affect the performance in a negative way. So it should be done within a time window where the traffic is at a minimum (researched here http://www.javabeat.net/articles/353-indexing-in-practice-using-mongodb-1.html).
Does anybody have experience on when and how often to create indexes in production (preferably with a large amount of data)? I am using Rails with Mongoid (http://mongoid.org/).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎假设必须定期重建索引。事实并非如此。当您写入相关数据时,MongoDB 会更新索引。
我看到的生产索引重建的唯一可能原因是:
You seem to assume you have to periodically rebuild indexes. This is not the case. MongoDB updates indexes as you write to the related data.
The only possible reason I can see for production index rebuilds are :