Insert performance and MongoTop

I am testing a insert of a document that is sized between 1.1mb to 1.5mb . During load testing I find that for the inital first 15 records the time taken seen on java client is higher between 200ms to 1500ms but in mongotop it shows time taken by mongodb is between 20 to 40 ms. after 15 records the time taken to insert is dropping to less than 100ms and averaging around 40ms. On the mongotop for same collection the time taken by mongodb is consistently low averaging 20ms. I want to ask is this because of the mongo java driver. The community mongodb server is version 4.0 and the mongo java client is version 3.12.4 and (mongo-driver-core-3.12.4.jar)

Please can anyone suggest where to detect the issue of initial slowness? We are not able to detect the cause of initial spike in time taken seen on the client. Thanks

Hi @Shivani_Chandna and welcome in the MongoDB Community :muscle: !

First of all, I would recommend to update the driver to 4.2.3.

https://mongodb.github.io/mongo-java-driver/4.2/driver/getting-started/installation/

3.12 is usually the legacy driver.

Please make sure to use the new sync or async driver.

Also updating MongoDB to 4.4 wouldn’t hurt the performance I guess as many things changed since 4.0.

Mongotop is only showing you how much time is spent during each second on each activities (read/write) in each collections. It’s not including how long it takes for you to load that file from disk in RAM with your app + process it in your client + send is over the network, etc.

Performance bottlenecks can come from many places… Network, IOPS, CPU, RAM, missing/too much/wrong indexes are usually the first suspects. If you didn’t use MongoDB Atlas, I could also suspect that you didn’t follow all the production notes to the letter and did some hazardous choices while settings up the OS.

It’s really impossible to tell you how to solve a performance issue without a deep analysis of the entire system.

Also, on a side note, jumbo documents are usually not the best idea to get good performances… If you can use a better data model, it could also definitely help.

Cheers,
Maxime.