Recently I notice a huge performance difference between doing multiple upserts (via bulk operations) vs an insert (multiple documents). I would like to know if I am correctly on this:
- Upsert/Updates will be like a
find()
andupdate()
so it does 2 things read and write - Insert will just write so its a lot faster
Thus the performance difference?
If this is the case, I wonder if I need a lot of writes regularly, instead of updating a document, I write a new document with a createdOn
field. Then to query, I will just query for documents, sorted by createdOn DESC
. I wonder if this is a good method? Or is there a better way?
- I do wonder if I have index on the collection, might it speed up the update? But wont this index slow down the write portion then?
- With the 2nd way, where I only do inserts, will it slow down then I have too many documents? Is it practical (to speed up the writes)?
- I have also tried increasing the connection pool size. Not sure whats the optimum, but I tried 20 and I see I can handle abt 20 queries per sec thru mongostat. I expected it to be alot higher.