SlideShare a Scribd company logo
1 of 26
Mongo DB
Note :
• This PPT is made from official documentation (mostly).
• Contains information as per my understanding.
• I might not know the answer to your question right now.
Agenda
• Introduction and features of Mongo DB
• Where to use ( and not to use )Mongo DB
• Supported and recommended platforms
• Installation , start/ stop services, imp terms.
• Architecture
• Does Mongo DB holds ACID ?
• Properties of Mongo and other considerations
• Backup
• What would be covered in the next session
• References
Introduction to Mongo DB
• Mongo is open-source document database.
• Provides high performance.
• Uses Rich Query Language.
• Provides High Availability. -- cluster
• Provides Horizontal Scalability. -- Shard
• Data in Mongo DB are stored in BSON format.
• Collection level Concurrency using MMAPv1 concept. ( incorporated in WiredTiger
too).
• Data consistency using Journaling
• Networking
• Support replicas
• Support indexes of many types
• Support Compressions
• Allows backups and restore features
• Cannot replace RDBMS or HADOOP systems
Where/when ( and where/when not)
to use Mongo DB
• Where/when to use :
– Used as primary data store for operational
applications with real time needs.
– Applications which use unstructured / semi –
structured data , large scalable and multi-
datacenter requirements.
• Where/when not to use :
• Applications using complex calculations.
• Finance data
• Any application which scans large subset of data.
Mongo DB supported platforms
Mongo DB recommended platforms
• As per official note , its advised to always use 64 bit.
• Moving to 3.2 version onwards, 32 bit has been deprecated.
• Current release as on Feb 17 is 3.4.2.
Mongo Installation
• Mongo DB community Edition
• Mongo DB Enterprise.
• Mongo DB instance stores its data files in /var/lib/mongo
• Logfiles are stored in /var/log/mongodb
• Executables go in /usr/bin
• User account created: mongod and mongo
• Default user mongo can be changed. Additional
permissions need to be given to data and log directories.
https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-red-hat/
Mongo Start / Stop / restart
• Start : sudo service mongod start
• Stop : sudo service mongod stop
• Restart : service mongod restart
• Remove :
1. yum erase $(rpm -qa | grep mongodb-org)
2. sudo rm -r /var/log/mongodb sudo rm -r
/var/lib/mongo
Imp Terms
mongod : mongod is the primary daemon
process for the MongoDB system.
mongos : mongos for "MongoDB Shard," is a
routing service for MongoDB shard
configurations.
mongo : mongo is an interactive JavaScript shell
interface to MongoDB.
• All Mongo service files, by default are stored
in : /usr/bin
Mongo configuration
• Mongo has a configuration file located in /etc by the
name mongod.conf.
• This contains all the configurations related information
, along with the location where the data will be stored.
• Mongo Db ( from version 3.2 onwards) used
WiredTiger storage engine, previous one was MMAPv1.
Mongo vs RDBMS mapping
MONGO RDBMS
Databases Databases
Collections Tables
Documents Rows
Fields Columns
Architecture of Mongo DB
• Mongo DB Nexus Architecture
• Mongo DB Flexible Storage Architecture
Does Mongo DB Holds ACID ?
• Atomicity , Consistency , Isolation and Durability.
• In one word – YES
• In detail – yes , but in limited sense , that is at the document [ row]
level.
• There is no possibility of atomic changes that span multiple
documents.
• Mongo DB handles consistency in its own way, shared in the next
slides.
• Isolation –Earlier version had complete server wide locks ,where as
version 2.2 onwards It became database wide.
• Durability –
• Does not give by default , but can be achieved using replicas but that
sacrifices performance.
• Eg: By keeping multiple replicas before considering a write operation finished.
Concurrency
• Concurrency is maintained using collection
[table]level locking from version 3 onwards.
• All collections have unique readers-writer lock
that allows multiple clients to modify
documents [ rows] in different collection [
tables] at the same time.
• Previous versions ( 2.2 through 2.6) allowed
concurrent read access per database , but only
one write operation per database.
Data Consistency
• Journaling :
• The storage engine uses checkpoints to provide a consistent view of data on disk
and allows recovery from the last checkpoint.
• Journaling needed to recover in unexpected shutdowns.
• With journaling , one journal record is created for each client initiated write
operation.
• Usual commits are done every 60 seconds however journal is committed every 100
milli seconds.
• Records the initial writes done by the initial write.
• The storage engine uses in-memory buffering for storing journal records.
• Can store upto 128 Kb of records.
• Storage engine syncs the buffered journals record on disks on certain criteria.
• Inspite of all this , in case of hard shutdowns , updates may be lost.
• Journals create journal files also which are created in a separate directory.
• Journaling continued
• Recovery using Journaling : 3 Step process:
– Looks in the data files to find the identifier of the last checkpoint.
– Searches in the journal files for the record that matches the identifier of the last checkpoint.
– Apply the operations in the journal files since the last checkpoint.
• MongoDB uses write ahead logging to an on-disk journal.
• Journaling guarantees that MongoDB can quickly recover write operations.
• Its advised to keep Journaling enabled.
• Read concern
• Two types :
– Majority
– Local
• Local is default .
• Local : Does not guarantee that the read data
would not be rolled back.
• Majority : Read when the data is written to many
replicas for more consistency.
• Write concern
• It is the level of acknowledgement requested from MongoDb write
operations.
• Weak : Data is written. No wait for acknowledgement.
• Stronger: Wait is done for acknowledgement.
• Write concerns can include the below fields :
• { w: <value>, j: <boolean>, wtimeout: <number> }
• W: is the number of instances the write should be propagated to.
• J : true | false : if the write has been written onto the Journal.
• Wtimeout : time limit to prevent write to block indefinitely.
Networking for Mongo
• Mongo should always run in a trusted env.
• Access only to servers and systems which really
access.
• By default , authorization ( control) is not
enabled and has to be enabled.
• Disable HTTP interface. Mongo uses HTTP
interface to check status of the server and run
queries.
• Connection pool should be optimized to around
100%-120% of the concurrent database requests.
Hardware Considerations
• Can run on commodity systems. No high end systems
needed.
• To run mongo with traditional storage
engine(MMAPv1) we 2 real cores or one physical core.
• Increasing the number of cores can improve
performance only upto some extent.
• Increasing RAM may help in improving performance by
reducing page faults.
• WiredTiger is multithreaded and additional CPUs help
in performance.
• Wired tiger uses some memory for caching also which
can be adjusted.
Other considerations
• Mongo Db supports compression and Encryption.
• Supports SSDs and SSDs and RAM helps in
performance.
• Running Mongo on NUMA [Non Uniform Access
Memory]* hardware causes problems.
• Mongo systems prefer RAID-10. Raid 5 does not
provide good performance.
• NFS is not recommended.
• Each OS has some specific settings which can be found
in the documentation.
• NUMA is computer memory design where the memory access time depends on the
memory location relative to processor.
Mongo DB backups
• Backup with MongoDB Cloud Manager
• Paid
• UI based.
• Backup with MongoDB OPS Manager
• Same as cloud Manager ,
• Paid
• UI based
• In Premise.
• Backup by copying underlying datafiles
• Using File system snapshot feature.
• Needs Journaling Enabled.
• To be taken separately on each shard after disabling the balancer.
• Backup with mongodump( and mongorestore)
• Efficient for small DBs.
• Does not work good for big databases.
• Has performance issues.
• Smaller than cp/rsync. ( Like expdp/impdp in Oracle).
• Backup using cp / rsync
• This is COLD backup.
• Writes need to be stopped for this to be a good copy.
What’s in the next session ?
• Security
• Replication
• Sharding
• working demo on:
– Installation
– Document Creation
– DML Statements / Indexes
– Backups
– Replication and Sharding ( if possible).
References
• https://docs.mongodb.com/v3.2/administration/production-
notes/
• http://openmymind.net/mongodb.pdf
• https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-
red-hat/
• https://www.mongodb.com/faq
• https://dzone.com/articles/how-acid-mongodb
• http://nosql.mypopescu.com/post/392868405/mongodb-
durability-a-tradeoff-to-be-aware-of
• https://www.mongodb.com/collateral/mongodb-architecture-
guide

More Related Content

What's hot

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
Challenges with MongoDB
Challenges with MongoDBChallenges with MongoDB
Challenges with MongoDBStone Gao
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDBEnoch Joshua
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesAlex Nguyen
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB InternalsSiraj Memon
 
MongoDB: An Introduction - june-2011
MongoDB:  An Introduction - june-2011MongoDB:  An Introduction - june-2011
MongoDB: An Introduction - june-2011Chris Westin
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJustin Smestad
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverMongoDB
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node jsHabilelabs
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentationHyphen Call
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational DatabasesChris Baglieri
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsSpringPeople
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 

What's hot (20)

Mongo db report
Mongo db reportMongo db report
Mongo db report
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Challenges with MongoDB
Challenges with MongoDBChallenges with MongoDB
Challenges with MongoDB
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDB
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB Internals
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
MongoDB: An Introduction - june-2011
MongoDB:  An Introduction - june-2011MongoDB:  An Introduction - june-2011
MongoDB: An Introduction - june-2011
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 

Viewers also liked

MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Shankar's mongo db presentation
Shankar's mongo db presentationShankar's mongo db presentation
Shankar's mongo db presentationShankar Kamble
 
Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDBIntro to NoSQL and MongoDB
Intro to NoSQL and MongoDBDATAVERSITY
 
Comparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statementsComparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statementsLucas Jellema
 
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028iis dahlia
 
Teaching Cloud to the Programmers of Tomorrow
Teaching Cloud to the Programmers of TomorrowTeaching Cloud to the Programmers of Tomorrow
Teaching Cloud to the Programmers of TomorrowMike Crabb
 
Getting started with MongoDB and PHP
Getting started with MongoDB and PHPGetting started with MongoDB and PHP
Getting started with MongoDB and PHPgates10gen
 
MongoDB London PHP
MongoDB London PHPMongoDB London PHP
MongoDB London PHPMike Dirolf
 
ConFoo - Migrating To Mongo Db
ConFoo - Migrating To Mongo DbConFoo - Migrating To Mongo Db
ConFoo - Migrating To Mongo DbContext.IO
 

Viewers also liked (16)

MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
Dineo
DineoDineo
Dineo
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo db
Mongo dbMongo db
Mongo db
 
Shankar's mongo db presentation
Shankar's mongo db presentationShankar's mongo db presentation
Shankar's mongo db presentation
 
Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDBIntro to NoSQL and MongoDB
Intro to NoSQL and MongoDB
 
Comparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statementsComparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statements
 
Mongo db m101j
Mongo db m101jMongo db m101j
Mongo db m101j
 
Administrasi MongoDB
Administrasi MongoDBAdministrasi MongoDB
Administrasi MongoDB
 
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
Konsep oop pada php dan mvc pada php framework, 1200631047 1200631018 1200631028
 
Teaching Cloud to the Programmers of Tomorrow
Teaching Cloud to the Programmers of TomorrowTeaching Cloud to the Programmers of Tomorrow
Teaching Cloud to the Programmers of Tomorrow
 
Getting started with MongoDB and PHP
Getting started with MongoDB and PHPGetting started with MongoDB and PHP
Getting started with MongoDB and PHP
 
MongoDB London PHP
MongoDB London PHPMongoDB London PHP
MongoDB London PHP
 
ConFoo - Migrating To Mongo Db
ConFoo - Migrating To Mongo DbConFoo - Migrating To Mongo Db
ConFoo - Migrating To Mongo Db
 

Similar to Mongo DB

Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment StrategiesMongoDB
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Norberto Leite
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseFITC
 
What'sNnew in 3.0 Webinar
What'sNnew in 3.0 WebinarWhat'sNnew in 3.0 Webinar
What'sNnew in 3.0 WebinarMongoDB
 
Benchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible DisastersBenchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible DisastersMongoDB
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadMarius Adrian Popa
 
Let the Tiger Roar!
Let the Tiger Roar!Let the Tiger Roar!
Let the Tiger Roar!MongoDB
 
Running MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWSRunning MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWSMongoDB
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentMongoDB
 
MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)
MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)
MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)MongoDB
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterChris Henry
 
MongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTigerMongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTigerWiredTiger
 
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...MongoDB
 
Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale Perforce
 
Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesMydbops
 

Similar to Mongo DB (20)

Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0
 
Deployment
DeploymentDeployment
Deployment
 
Tuning Linux for MongoDB
Tuning Linux for MongoDBTuning Linux for MongoDB
Tuning Linux for MongoDB
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
 
What'sNnew in 3.0 Webinar
What'sNnew in 3.0 WebinarWhat'sNnew in 3.0 Webinar
What'sNnew in 3.0 Webinar
 
Benchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible DisastersBenchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible Disasters
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
 
Let the Tiger Roar!
Let the Tiger Roar!Let the Tiger Roar!
Let the Tiger Roar!
 
Tuning linux for mongo db
Tuning linux for mongo dbTuning linux for mongo db
Tuning linux for mongo db
 
Running MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWSRunning MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWS
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)
MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)
MongoDB 3.0 and WiredTiger (Event: An Evening with MongoDB Dallas 3/10/15)
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
 
MongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTigerMongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTiger
 
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
 
Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale
 
Evolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best PracticesEvolution of MongoDB Replicaset and Its Best Practices
Evolution of MongoDB Replicaset and Its Best Practices
 

Mongo DB

  • 1. Mongo DB Note : • This PPT is made from official documentation (mostly). • Contains information as per my understanding. • I might not know the answer to your question right now.
  • 2. Agenda • Introduction and features of Mongo DB • Where to use ( and not to use )Mongo DB • Supported and recommended platforms • Installation , start/ stop services, imp terms. • Architecture • Does Mongo DB holds ACID ? • Properties of Mongo and other considerations • Backup • What would be covered in the next session • References
  • 3. Introduction to Mongo DB • Mongo is open-source document database. • Provides high performance. • Uses Rich Query Language. • Provides High Availability. -- cluster • Provides Horizontal Scalability. -- Shard • Data in Mongo DB are stored in BSON format. • Collection level Concurrency using MMAPv1 concept. ( incorporated in WiredTiger too). • Data consistency using Journaling • Networking • Support replicas • Support indexes of many types • Support Compressions • Allows backups and restore features • Cannot replace RDBMS or HADOOP systems
  • 4. Where/when ( and where/when not) to use Mongo DB • Where/when to use : – Used as primary data store for operational applications with real time needs. – Applications which use unstructured / semi – structured data , large scalable and multi- datacenter requirements. • Where/when not to use : • Applications using complex calculations. • Finance data • Any application which scans large subset of data.
  • 5. Mongo DB supported platforms
  • 6. Mongo DB recommended platforms • As per official note , its advised to always use 64 bit. • Moving to 3.2 version onwards, 32 bit has been deprecated. • Current release as on Feb 17 is 3.4.2.
  • 7. Mongo Installation • Mongo DB community Edition • Mongo DB Enterprise. • Mongo DB instance stores its data files in /var/lib/mongo • Logfiles are stored in /var/log/mongodb • Executables go in /usr/bin • User account created: mongod and mongo • Default user mongo can be changed. Additional permissions need to be given to data and log directories. https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-red-hat/
  • 8. Mongo Start / Stop / restart • Start : sudo service mongod start • Stop : sudo service mongod stop • Restart : service mongod restart • Remove : 1. yum erase $(rpm -qa | grep mongodb-org) 2. sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongo
  • 9. Imp Terms mongod : mongod is the primary daemon process for the MongoDB system. mongos : mongos for "MongoDB Shard," is a routing service for MongoDB shard configurations. mongo : mongo is an interactive JavaScript shell interface to MongoDB.
  • 10. • All Mongo service files, by default are stored in : /usr/bin
  • 11. Mongo configuration • Mongo has a configuration file located in /etc by the name mongod.conf. • This contains all the configurations related information , along with the location where the data will be stored. • Mongo Db ( from version 3.2 onwards) used WiredTiger storage engine, previous one was MMAPv1.
  • 12. Mongo vs RDBMS mapping MONGO RDBMS Databases Databases Collections Tables Documents Rows Fields Columns
  • 13. Architecture of Mongo DB • Mongo DB Nexus Architecture
  • 14. • Mongo DB Flexible Storage Architecture
  • 15. Does Mongo DB Holds ACID ? • Atomicity , Consistency , Isolation and Durability. • In one word – YES • In detail – yes , but in limited sense , that is at the document [ row] level. • There is no possibility of atomic changes that span multiple documents. • Mongo DB handles consistency in its own way, shared in the next slides. • Isolation –Earlier version had complete server wide locks ,where as version 2.2 onwards It became database wide. • Durability – • Does not give by default , but can be achieved using replicas but that sacrifices performance. • Eg: By keeping multiple replicas before considering a write operation finished.
  • 16. Concurrency • Concurrency is maintained using collection [table]level locking from version 3 onwards. • All collections have unique readers-writer lock that allows multiple clients to modify documents [ rows] in different collection [ tables] at the same time. • Previous versions ( 2.2 through 2.6) allowed concurrent read access per database , but only one write operation per database.
  • 17. Data Consistency • Journaling : • The storage engine uses checkpoints to provide a consistent view of data on disk and allows recovery from the last checkpoint. • Journaling needed to recover in unexpected shutdowns. • With journaling , one journal record is created for each client initiated write operation. • Usual commits are done every 60 seconds however journal is committed every 100 milli seconds. • Records the initial writes done by the initial write. • The storage engine uses in-memory buffering for storing journal records. • Can store upto 128 Kb of records. • Storage engine syncs the buffered journals record on disks on certain criteria. • Inspite of all this , in case of hard shutdowns , updates may be lost. • Journals create journal files also which are created in a separate directory.
  • 18. • Journaling continued • Recovery using Journaling : 3 Step process: – Looks in the data files to find the identifier of the last checkpoint. – Searches in the journal files for the record that matches the identifier of the last checkpoint. – Apply the operations in the journal files since the last checkpoint. • MongoDB uses write ahead logging to an on-disk journal. • Journaling guarantees that MongoDB can quickly recover write operations. • Its advised to keep Journaling enabled.
  • 19. • Read concern • Two types : – Majority – Local • Local is default . • Local : Does not guarantee that the read data would not be rolled back. • Majority : Read when the data is written to many replicas for more consistency.
  • 20. • Write concern • It is the level of acknowledgement requested from MongoDb write operations. • Weak : Data is written. No wait for acknowledgement. • Stronger: Wait is done for acknowledgement. • Write concerns can include the below fields : • { w: <value>, j: <boolean>, wtimeout: <number> } • W: is the number of instances the write should be propagated to. • J : true | false : if the write has been written onto the Journal. • Wtimeout : time limit to prevent write to block indefinitely.
  • 21. Networking for Mongo • Mongo should always run in a trusted env. • Access only to servers and systems which really access. • By default , authorization ( control) is not enabled and has to be enabled. • Disable HTTP interface. Mongo uses HTTP interface to check status of the server and run queries. • Connection pool should be optimized to around 100%-120% of the concurrent database requests.
  • 22. Hardware Considerations • Can run on commodity systems. No high end systems needed. • To run mongo with traditional storage engine(MMAPv1) we 2 real cores or one physical core. • Increasing the number of cores can improve performance only upto some extent. • Increasing RAM may help in improving performance by reducing page faults. • WiredTiger is multithreaded and additional CPUs help in performance. • Wired tiger uses some memory for caching also which can be adjusted.
  • 23. Other considerations • Mongo Db supports compression and Encryption. • Supports SSDs and SSDs and RAM helps in performance. • Running Mongo on NUMA [Non Uniform Access Memory]* hardware causes problems. • Mongo systems prefer RAID-10. Raid 5 does not provide good performance. • NFS is not recommended. • Each OS has some specific settings which can be found in the documentation. • NUMA is computer memory design where the memory access time depends on the memory location relative to processor.
  • 24. Mongo DB backups • Backup with MongoDB Cloud Manager • Paid • UI based. • Backup with MongoDB OPS Manager • Same as cloud Manager , • Paid • UI based • In Premise. • Backup by copying underlying datafiles • Using File system snapshot feature. • Needs Journaling Enabled. • To be taken separately on each shard after disabling the balancer. • Backup with mongodump( and mongorestore) • Efficient for small DBs. • Does not work good for big databases. • Has performance issues. • Smaller than cp/rsync. ( Like expdp/impdp in Oracle). • Backup using cp / rsync • This is COLD backup. • Writes need to be stopped for this to be a good copy.
  • 25. What’s in the next session ? • Security • Replication • Sharding • working demo on: – Installation – Document Creation – DML Statements / Indexes – Backups – Replication and Sharding ( if possible).
  • 26. References • https://docs.mongodb.com/v3.2/administration/production- notes/ • http://openmymind.net/mongodb.pdf • https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on- red-hat/ • https://www.mongodb.com/faq • https://dzone.com/articles/how-acid-mongodb • http://nosql.mypopescu.com/post/392868405/mongodb- durability-a-tradeoff-to-be-aware-of • https://www.mongodb.com/collateral/mongodb-architecture- guide