未加星标

The Perils of Building Indexes on MongoDB

字体大小 | |
[数据库(综合) 所属分类 数据库(综合) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Indexes are a critical part of any database operation. Defining the right indexes can make a huge difference to the performance of your database servers. However, creating indexes in MongoDB has several pitfalls that you need to be aware of for your day to day operations. MongoDB at a high level supports three techniques to build indexes on your collections

1. Foreground Index Build

When you build an index in the foreground it blocks all other operations on the database on a large collection, this can be several hours. This implies that your database is down for the duration of the index build. Given that this is the default mode of building indexes it is not surprising that a lot of developers shoot themselves in the foot triggering accidental index builds. There is really no good reason to trigger a foreground index build on a production server (unless you know that the collection has a small amount of data)

2. Background Index Build

As the name implies the background indexing process builds the index in the background without affecting the availability of your database server. However, it is still a resource intensive operation and you should expect to see performance degradation. Also since it is happening in the background it can take a lot longer to build than the foreground indexes. In the previous versions of MongoDB (< 2.6) when you did a background index build on the primary of a replica set it would run as “foreground” build on the secondary servers, thankfully it is no longer the case it is background build on all the nodes. If a background index build is interrupted it will resume as a foreground index build on server restart.

3. Rolling Index Build

The rolling index build process builds the index on only one node at a time. It goes something like this

1. Rotate a secondary node out of the replica set (you can do this by changing ports or restarting in standalone mode)

2. Build the index on this node in the foreground. Once the index is built, rotate the node back into the replica set

3. Once the node has caught up to the changes move on to the next node. If the next node is the primary you will need to do a rs.stepDown() to make it into a secondary.

4. Rinse and repeat.

More details of the index build process are in the MongoDB documentation .

Using rolling index builds you can build an index without any significant performance impactfor your application. However there is failover involved so your application should be able to handle that (which it needs to anyways).

Can you do a rolling index build if you don’t have a replica set? Unfortunately for standalone instances, the only option is a “Background index build”.

The Rolling index build is our favored approach to building indexes at ScaleGrid. We even provide a UI and make it easy for you to kick off the whole process from our UI. Our backend will do all the orchestration necessary for the full index build it will trigger a server by server index build. You just need to point and click!


The Perils of Building Indexes on MongoDB

As always, if you have further questions you can reach out to us at [email protected]

本文数据库(综合)相关术语:系统安全软件

主题: MongoDB
分页:12
转载请注明
本文标题:The Perils of Building Indexes on MongoDB
本站链接:http://www.codesec.net/view/531399.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(40)