Time difference between background and foreground index creation in MongoDB

Dataset

Here are the stats of the collection:

db.getCollection('test_collection').stats()
{
"ns" : "test.test_collection",
"size" : 39910174160.0,
"count" : 100886027,
"avgObjSize" : 395,
"storageSize" : 15832367104.0,
"capped" : false,
"wiredTiger": {...},
"nindexes" : 2,
"totalIndexSize" : 4183117824.0,
"indexSizes" : {
"_id_" : 1781731328.0,
"fullname_1" : 2401386496.0
},
"ok" : 1.0
}

Hardware

I used a single MongoDB node created on Azure.Standard DS2 v2 (2 vcpus, 7 GB memory) instance.
Disk: 256 GB Premium SSD, IOPS 1100, Throughput limit 125 MB/s

Creation of the index

Creating an index is simple:

Results

The background process took a total of 153 minutes and the foreground took 29 minutes.

Conclude

Of course, the foreground index building is faster. This is not a big surprise but I didn’t expect such a big time difference, and according to the data, it grows exponentially. So if you have two times more data the background index building will take 4 times more.

--

--

I am a technical manager and problem solver. A back-end developer also a father, sport man, author of an e-book and audiobook (Hungarian)

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Péter Karakas

Péter Karakas

I am a technical manager and problem solver. A back-end developer also a father, sport man, author of an e-book and audiobook (Hungarian)