15. MongoDB : MongoDB Performance
Commands to check STATS ###########################################
//execute below command from bin , before that u should have started mongod
//below files exist in bin folder
mongostat; //check statistics
mongotop; // to track all read and write activity
db.serverStatus();
db.stats(); //number of collection, objects etc..
db.items.stats(); //collection level statistics
Journaling Mechanics ###########################################
- If we launch MongoD in Journal mode, then all write 1st goes to Journal before it goes to DB
-- mongod.exe --dbpath D:\mongoDBDatabase --rest --journal
- Adv : fast and cheap (eg: while writing if server goes down, then when ever server comes up it takes from journal later)
Storage Engines ###########################################
1> memory map1 - read heavy operation , this is based on m-map files.
2> Wired-Tiger - heavy write operation, eg: facebook, twitter etc.
- complex - updates possible
- Uses commit chckpoint - after every 60 secs moving data from Journal to memory
Index - UnderIndex/OverIndex - poor design ###########################################
- All indexes are written to RAM, only if RAM is full then it writes to Harddisc which is very slow.
- Usually - in production 10% of Harddisck RAM shoud be there
Eg: 500 GB HD, 50G GB RAM
Mongoos ###########################################
- Always use Mongoos tool - which handles all connection pool internally
Backup data ###########################################
- 1> copy paste all collections which is inside "D://mongoDBDatabase" all "wt" files.
always enable journal if you need backup
- 2> mongodump //reads data from a mongDB database and creates BSON files. (it takes only documents as backup, it wont take index's, takes what index on what field)
mongorestore //
Lock DB during backup ###########################################
- use admin
- db.runCommand({"fsync":1, "lock":1}); //lock during backup
- db.$cmd.sys.unlock.findOne(); //unlock after backup is done.
No comments:
Post a Comment