Mongodb – Inserts very slow near the end of dataset

mongodb

I'm trying to insert Whois Records ( domain name and relevant info) into MongoDB after parsing them from CSV files. I currently have a collection for each TLD such as .com, .org, etc.

During the initial insertion of the records( such as the quick insertions of the least populated and obscure TLDs and initial .com etc insertion ), I get decent insert speeds of about 10k-15k inserts per second.

However, this slows to a crawl, partway through. Since MongoDB uses a B-tree for indexing primaries, shouldn't the performance slowdown due to database size be minimal?

Extra Information if relevant: MongoDB 3.4, WiredTiger, Java 1.8, primary index is the domain name itself

Best Answer

You have run out of resources!

With 202M records, even one record would be only 64 bytes (you can check with db.collection.stats().avgObjSize), the size is 12GB and then comes index. The optimal situation is when active data, (index and data) is in the memory. This case it is NOT. So, mongod starts using disk heavily and if your disk is not high IOPS (SSD base) and low latency base, your machine starts slowing down.

Can you (for start) increase memory to (at least) 16 - 32GB?

Related Question