While MongoDB doesn't require any fixed schema, there are times we would like to migrate from one structure to another.
I was dealing with a small dataset (~200K) recently, and decided to loop existing data, transform data model and insert to new collections. It turned out our vps wasn't that powerful, using php driver I can only get to about ~300 insertion/sec, after having ensured following:
- no index before insertion.
- use batch insert as much as possible.
I wonder if I have simply picked the wrong migration path, or if there are some best practice when dealing with schema change in MongoDB?
After taking in some suggestions, I changed the write concern to 0 during migration, and this is what i have observed:
- Insertions are still not as fast as expected, max at ~500 insertion/sec
- After insertion completed, indexing go through very quickly, probably due to the fact the
ensureIndex
is fire-and-forget withw=0
? - Remaining update took a while to start, probably due to the fact the indexing operations are blocking? Then it appear to ran at a varying speed (previously it was running consistently slower), again maybe indexing were taking place.
- CPU and IO were fine. cpu mostly had about 90% idle, and IO wait were less than 10%.
Besides not using our PHP ORM for the migration, are there more possibility for optimization?