SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
Apr-26-2017
Exploring the replication
and sharding in MongoDB
• Master degree, Software Engineering
• Working with databases since 2007
• MySQL, LAMP, Linux since 2010
• Pythian OSDB managed services since 2014
• Lead Database Consultant since 2016
• C100DBA: MongoDB certified DBA
https://mk.linkedin.com/in/igorle @igorLE
About me
© 2017 Pythian. Confidential
Overview
• What is replica set, how replication works, replication concepts
• Replica set features, deployment architectures
• Vertical vs Horizontal scaling
• What is a sharded cluster in MongoDB
• Cluster components - shards, config servers, mongos
• Shard keys and chunks
• Hashed vs range based sharding
• QA
© 2017 Pythian. Confidential
Replication
• Group of mongod processes that maintain the same data set
• Redundancy and high availability
• Increased read capacity
© 2017 Pythian. Confidential
Replication concept
1. Write operations go to the Primary node
2. All changes are recorded into operations log
3. Asynchronous replication to Secondary
4. Secondaries copy the Primary oplog
5. Secondary can use sync source Secondary*
Automatic failover on Primary failure
*settings.chainingAllowed (true by default)
© 2017 Pythian. Confidential
2. oplog
1.
3. 3.
4. 4.
5.
Replica set oplog
• Special capped collection that keeps a rolling record of all
operations that modify the data stored in the databases
• Idempotent
• Default oplog size
For Unix and Windows systems
Storage Engine Default Oplog Size Lower Bound Upper Bound
In-memory 5% of physical memory 50MB 50GB
WiredTiger 5% of free disk space 990MB 50GB
MMAPv1 5% of free disk space 990MB 50GB
© 2017 Pythian. Confidential
● Start each server with config options for replSet
/usr/bin/mongod --replSet "myRepl"
● Initiate the replica set on one node - rs.initialize()
● Verify the configuration - rs.conf()
Deployment
© 2017 Pythian. Confidential
Node 2 Node 3
rs.initialize() Node 1
• Add the rest of the nodes - rs.add() on the Primary node
rs.add(“node2:27017”) , rs.add(“node3:27017”)
• Check the status of the replica set - rs.status()
Deployment
© 2017 Pythian. Confidential
Node 2 Node 3
rs.add()
Configuration options
• 50 members per replica set (7 voting members)
• Arbiter node
• Priority 0 node
• Hidden node
• Delayed node
• Write concern
• Read preference
© 2017 Pythian. Confidential
Arbiter node
• Does not hold copy of data
• Votes in elections
hidden : true
© 2017 Pythian. Confidential
Arbiter
Priority 0 node
Priority - floating point (i.e. decimal) number between 0 and 1000
• Never becomes primary
• Visible to application
• Node with highest priority is eventually elected as Primary
© 2017 Pythian. Confidential
Secondary
priority : 0
Hidden node
• Never becomes primary
• Not visible to application
• Use cases
○ reporting
○ backups
hidden : true
© 2017 Pythian. Confidential
hidden: true priority:0
Secondary
hidden : true priority : 0
Delayed node
• Must be priority 0 member
• Should be hidden member (not mandatory)
• Has votes 1 by default
• Considerations (oplog size)
• Mainly used for backups
© 2017 Pythian. Confidential
Secondary
slaveDelay : 3600
priority : 0
hidden : true
Write concern
{ w: <value>, j: <boolean>, wtimeout: <number> }
● w - number of mongod instances that
acknowledged the write operation
● j - acknowledgement that the write operation
has been written to the journal
● wtimeout - time limit to prevent write operations
from blocking indefinitely
© 2017 Pythian. Confidential
Read preference
How read operations are routed to replica set members
1. primary (by default)
2. primaryPreferred
3. secondary
4. secondaryPreferred
5. nearest (least network latency)
MongoDB 3.4 maxStalenessSeconds ( >= 90 seconds)
© 2017 Pythian. Confidential
Driver
1.
2. 2.
2.
3. 3.4.4.
4.
5. 5.
5.
• CPU
• RAM
• DISK
Scaling (vertical)
© 2017 Pythian. Confidential
• Method for distributing data across multiple machines
• Splitting data across multiple horizontal partitions
Scaling (horizontal) - Sharding
© 2017 Pythian. Confidential
Sharding with MongoDB
Shard
© 2017 Pythian. Confidential
Shard
Data
Sharding with MongoDB
• Shard/Replica set
(subset of the sharded data)
• Config servers
(metadata and config settings)
• mongos
(query router, cluster interface)
© 2017 Pythian. Confidential
Shard
Data
Sharding with MongoDB
• Shard/Replica set
(subset of the sharded data)
• Config servers
(metadata and config settings)
• mongos
(query router, cluster interface)
sh.addShard("shardName")
© 2017 Pythian. Confidential
A B
Shards
• Contains subset of sharded data
• Replica set for redundancy and HA
• Primary shard
• Non sharded collections
• --shardsvr in config file (port 27018)
© 2017 Pythian. Confidential
Config servers
• Config servers as replica set only (>= 3.4)
• Stores the metadata for sharded cluster in
config database
• Authentication configuration information in
admin database
• Holds balancer on Primary node (>= 3.4)
• --configsvr in config file (port 27019)
© 2017 Pythian. Confidential
mongos
• Caching metadata from config servers
• Routes queries to shards
• No persistent state
• Updates cache on metadata changes
• Holds balancer (mongodb <= 3.2)
• mongos version 3.4 can not connect to
earlier mongod version
© 2017 Pythian. Confidential
Sharding collection
• Enable sharding on database
sh.enableSharding("users")
• Shard collection
sh.shardCollection("users.history", { user_id : 1 } )
• Shard key - indexed key that exists in every document
○ range based
sh.shardCollection("users.history", { user_id : 1 } )
○ hashed based
sh.shardCollection( "users.history", { user_id : "hashed" } )
© 2017 Pythian. Confidential
Shard keys and chunks
Choosing Shard key
• Large Shard Key Cardinality
• Low Shard Key Frequency
• Non-Monotonically changing shard keys
Chunks
• A contiguous range of shard key values within a particular shard
• Inclusive lower and exclusive upper range based on shard key
• Default size of 64MB
© 2017 Pythian. Confidential
Ranged sharding
• Dividing data into contiguous ranges determined by the shard key values
• Documents with “close” shard key values are likely to be in the same
chunk or shard
• Query Isolation - more likely to target single shard
© 2017 Pythian. Confidential
Hashed sharding
• Uses a hashed index of a single field as the shard key to partition data
• More even data distribution at the cost of reducing Query Isolation
• Applications do not need to compute hashes
• Keys that change monotonically like ObjectId or timestamps are ideal
© 2017 Pythian. Confidential
Shard keys limitations
• Must be ascending indexed key or indexed compound keys that
exists in every document in the collection
• Cannot be multikey index, a text index or a geospatial index
• Cannot exceed 512 bytes
• Immutable key - can not be updated/changed
• Update operations that affect a single document must include the
shard key or the _id field
• No option for sharding if unique indexes on other fields exist
• No option for second unique index if the shard key is unique index
© 2017 Pythian. Confidential
Summary
• Replica set with odd number of voting members
• Hidden or Delayed member for dedicated functions (backups …)
• Dataset fits into single server, keep unsharded deployment
• Horizontal scaling - shards running as replica sets
• Shard keys are immutable with max size of 512 bytes
• Shard keys must exists in every document in the collection
• Ranged sharding may not distribute the data evenly
• Hashed sharding distributes the data randomly
© 2017 Pythian. Confidential
Questions?
© 2017 Pythian. Confidential
We’re Hiring!
https://www.pythian.com/careers/
© 2017 Pythian. Confidential

Contenu connexe

Tendances

MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at ScaleMongoDB
 
Dynamodb Presentation
Dynamodb PresentationDynamodb Presentation
Dynamodb Presentationadvaitdeo
 
[오픈소스컨설팅] SELinux : Stop Disabling SELinux
[오픈소스컨설팅] SELinux : Stop Disabling SELinux[오픈소스컨설팅] SELinux : Stop Disabling SELinux
[오픈소스컨설팅] SELinux : Stop Disabling SELinuxOpen Source Consulting
 
High Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal CloudHigh Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal CloudMongoDB
 
Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...
Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...
Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...Edureka!
 
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...Cathrine Wilhelmsen
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimizationUsman Tariq
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsIgor Donchovski
 
Introduction to Azure Databricks
Introduction to Azure DatabricksIntroduction to Azure Databricks
Introduction to Azure DatabricksJames Serra
 
Replacing Tape Backup with Cloud-Enabled Solutions by Index Engines
Replacing Tape Backup with Cloud-Enabled Solutions by Index EnginesReplacing Tape Backup with Cloud-Enabled Solutions by Index Engines
Replacing Tape Backup with Cloud-Enabled Solutions by Index EnginesAmazon Web Services
 
AWS Cloud organizations presentation
AWS Cloud organizations presentationAWS Cloud organizations presentation
AWS Cloud organizations presentationTATA LILIAN SHULIKA
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to ShardingMongoDB
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational DatabasesChris Baglieri
 
Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)Daniel Toomey
 

Tendances (20)

MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at Scale
 
Dynamodb Presentation
Dynamodb PresentationDynamodb Presentation
Dynamodb Presentation
 
[오픈소스컨설팅] SELinux : Stop Disabling SELinux
[오픈소스컨설팅] SELinux : Stop Disabling SELinux[오픈소스컨설팅] SELinux : Stop Disabling SELinux
[오픈소스컨설팅] SELinux : Stop Disabling SELinux
 
High Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal CloudHigh Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal Cloud
 
AWS Account Best Practices
AWS Account Best PracticesAWS Account Best Practices
AWS Account Best Practices
 
ASH and AWR on DB12c
ASH and AWR on DB12cASH and AWR on DB12c
ASH and AWR on DB12c
 
Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...
Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...
Big Data Tutorial For Beginners | What Is Big Data | Big Data Tutorial | Hado...
 
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...
Lessons Learned: Understanding Pipeline Pricing in Azure Data Factory and Azu...
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimization
 
Join query
Join queryJoin query
Join query
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica Sets
 
Introduction to Azure Databricks
Introduction to Azure DatabricksIntroduction to Azure Databricks
Introduction to Azure Databricks
 
Replacing Tape Backup with Cloud-Enabled Solutions by Index Engines
Replacing Tape Backup with Cloud-Enabled Solutions by Index EnginesReplacing Tape Backup with Cloud-Enabled Solutions by Index Engines
Replacing Tape Backup with Cloud-Enabled Solutions by Index Engines
 
AWS Cloud organizations presentation
AWS Cloud organizations presentationAWS Cloud organizations presentation
AWS Cloud organizations presentation
 
Modern data warehouse
Modern data warehouseModern data warehouse
Modern data warehouse
 
AWS Analytics
AWS AnalyticsAWS Analytics
AWS Analytics
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to Sharding
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
 
Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)
 

Similaire à Exploring the replication and sharding in MongoDB

MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at RestMydbops
 
Data dictionary pl17
Data dictionary pl17Data dictionary pl17
Data dictionary pl17Ståle Deraas
 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16Sanjay Manwani
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceSasidhar Gogulapati
 
Pimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion UsersPimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion UsersForgeRock
 
MariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLMariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLColin Charles
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...Severalnines
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDBIgor Donchovski
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Mydbops
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Mydbops
 
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...Big Data Spain
 
Oracle big data appliance and solutions
Oracle big data appliance and solutionsOracle big data appliance and solutions
Oracle big data appliance and solutionssolarisyougood
 
Move your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in CloudMove your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in CloudCAMMS
 
Webinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case StudyWebinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case StudyCeph Community
 

Similaire à Exploring the replication and sharding in MongoDB (20)

How to scale MongoDB
How to scale MongoDBHow to scale MongoDB
How to scale MongoDB
 
Introduction to Mongodb
Introduction to MongodbIntroduction to Mongodb
Introduction to Mongodb
 
Novinky v Oracle Database 18c
Novinky v Oracle Database 18cNovinky v Oracle Database 18c
Novinky v Oracle Database 18c
 
MySQL Data Encryption at Rest
MySQL Data Encryption at RestMySQL Data Encryption at Rest
MySQL Data Encryption at Rest
 
Data dictionary pl17
Data dictionary pl17Data dictionary pl17
Data dictionary pl17
 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & Performance
 
Pimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion UsersPimping the ForgeRock Identity Platform for a Billion Users
Pimping the ForgeRock Identity Platform for a Billion Users
 
MariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQLMariaDB Server Compatibility with MySQL
MariaDB Server Compatibility with MySQL
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Mongo db 3.4 Overview
Mongo db 3.4 OverviewMongo db 3.4 Overview
Mongo db 3.4 Overview
 
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
MySQL Load Balancers - Maxscale, ProxySQL, HAProxy, MySQL Router & nginx - A ...
 
Hadoop
HadoopHadoop
Hadoop
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDB
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding
 
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
 
Oracle big data appliance and solutions
Oracle big data appliance and solutionsOracle big data appliance and solutions
Oracle big data appliance and solutions
 
Move your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in CloudMove your on prem data to a lake in a Lake in Cloud
Move your on prem data to a lake in a Lake in Cloud
 
Webinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case StudyWebinar - DreamObjects/Ceph Case Study
Webinar - DreamObjects/Ceph Case Study
 

Dernier

An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 

Dernier (20)

An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 

Exploring the replication and sharding in MongoDB

  • 2. • Master degree, Software Engineering • Working with databases since 2007 • MySQL, LAMP, Linux since 2010 • Pythian OSDB managed services since 2014 • Lead Database Consultant since 2016 • C100DBA: MongoDB certified DBA https://mk.linkedin.com/in/igorle @igorLE About me © 2017 Pythian. Confidential
  • 3. Overview • What is replica set, how replication works, replication concepts • Replica set features, deployment architectures • Vertical vs Horizontal scaling • What is a sharded cluster in MongoDB • Cluster components - shards, config servers, mongos • Shard keys and chunks • Hashed vs range based sharding • QA © 2017 Pythian. Confidential
  • 4. Replication • Group of mongod processes that maintain the same data set • Redundancy and high availability • Increased read capacity © 2017 Pythian. Confidential
  • 5. Replication concept 1. Write operations go to the Primary node 2. All changes are recorded into operations log 3. Asynchronous replication to Secondary 4. Secondaries copy the Primary oplog 5. Secondary can use sync source Secondary* Automatic failover on Primary failure *settings.chainingAllowed (true by default) © 2017 Pythian. Confidential 2. oplog 1. 3. 3. 4. 4. 5.
  • 6. Replica set oplog • Special capped collection that keeps a rolling record of all operations that modify the data stored in the databases • Idempotent • Default oplog size For Unix and Windows systems Storage Engine Default Oplog Size Lower Bound Upper Bound In-memory 5% of physical memory 50MB 50GB WiredTiger 5% of free disk space 990MB 50GB MMAPv1 5% of free disk space 990MB 50GB © 2017 Pythian. Confidential
  • 7. ● Start each server with config options for replSet /usr/bin/mongod --replSet "myRepl" ● Initiate the replica set on one node - rs.initialize() ● Verify the configuration - rs.conf() Deployment © 2017 Pythian. Confidential Node 2 Node 3 rs.initialize() Node 1
  • 8. • Add the rest of the nodes - rs.add() on the Primary node rs.add(“node2:27017”) , rs.add(“node3:27017”) • Check the status of the replica set - rs.status() Deployment © 2017 Pythian. Confidential Node 2 Node 3 rs.add()
  • 9. Configuration options • 50 members per replica set (7 voting members) • Arbiter node • Priority 0 node • Hidden node • Delayed node • Write concern • Read preference © 2017 Pythian. Confidential
  • 10. Arbiter node • Does not hold copy of data • Votes in elections hidden : true © 2017 Pythian. Confidential Arbiter
  • 11. Priority 0 node Priority - floating point (i.e. decimal) number between 0 and 1000 • Never becomes primary • Visible to application • Node with highest priority is eventually elected as Primary © 2017 Pythian. Confidential Secondary priority : 0
  • 12. Hidden node • Never becomes primary • Not visible to application • Use cases ○ reporting ○ backups hidden : true © 2017 Pythian. Confidential hidden: true priority:0 Secondary hidden : true priority : 0
  • 13. Delayed node • Must be priority 0 member • Should be hidden member (not mandatory) • Has votes 1 by default • Considerations (oplog size) • Mainly used for backups © 2017 Pythian. Confidential Secondary slaveDelay : 3600 priority : 0 hidden : true
  • 14. Write concern { w: <value>, j: <boolean>, wtimeout: <number> } ● w - number of mongod instances that acknowledged the write operation ● j - acknowledgement that the write operation has been written to the journal ● wtimeout - time limit to prevent write operations from blocking indefinitely © 2017 Pythian. Confidential
  • 15. Read preference How read operations are routed to replica set members 1. primary (by default) 2. primaryPreferred 3. secondary 4. secondaryPreferred 5. nearest (least network latency) MongoDB 3.4 maxStalenessSeconds ( >= 90 seconds) © 2017 Pythian. Confidential Driver 1. 2. 2. 2. 3. 3.4.4. 4. 5. 5. 5.
  • 16. • CPU • RAM • DISK Scaling (vertical) © 2017 Pythian. Confidential
  • 17. • Method for distributing data across multiple machines • Splitting data across multiple horizontal partitions Scaling (horizontal) - Sharding © 2017 Pythian. Confidential
  • 18. Sharding with MongoDB Shard © 2017 Pythian. Confidential Shard Data
  • 19. Sharding with MongoDB • Shard/Replica set (subset of the sharded data) • Config servers (metadata and config settings) • mongos (query router, cluster interface) © 2017 Pythian. Confidential Shard Data
  • 20. Sharding with MongoDB • Shard/Replica set (subset of the sharded data) • Config servers (metadata and config settings) • mongos (query router, cluster interface) sh.addShard("shardName") © 2017 Pythian. Confidential A B
  • 21. Shards • Contains subset of sharded data • Replica set for redundancy and HA • Primary shard • Non sharded collections • --shardsvr in config file (port 27018) © 2017 Pythian. Confidential
  • 22. Config servers • Config servers as replica set only (>= 3.4) • Stores the metadata for sharded cluster in config database • Authentication configuration information in admin database • Holds balancer on Primary node (>= 3.4) • --configsvr in config file (port 27019) © 2017 Pythian. Confidential
  • 23. mongos • Caching metadata from config servers • Routes queries to shards • No persistent state • Updates cache on metadata changes • Holds balancer (mongodb <= 3.2) • mongos version 3.4 can not connect to earlier mongod version © 2017 Pythian. Confidential
  • 24. Sharding collection • Enable sharding on database sh.enableSharding("users") • Shard collection sh.shardCollection("users.history", { user_id : 1 } ) • Shard key - indexed key that exists in every document ○ range based sh.shardCollection("users.history", { user_id : 1 } ) ○ hashed based sh.shardCollection( "users.history", { user_id : "hashed" } ) © 2017 Pythian. Confidential
  • 25. Shard keys and chunks Choosing Shard key • Large Shard Key Cardinality • Low Shard Key Frequency • Non-Monotonically changing shard keys Chunks • A contiguous range of shard key values within a particular shard • Inclusive lower and exclusive upper range based on shard key • Default size of 64MB © 2017 Pythian. Confidential
  • 26. Ranged sharding • Dividing data into contiguous ranges determined by the shard key values • Documents with “close” shard key values are likely to be in the same chunk or shard • Query Isolation - more likely to target single shard © 2017 Pythian. Confidential
  • 27. Hashed sharding • Uses a hashed index of a single field as the shard key to partition data • More even data distribution at the cost of reducing Query Isolation • Applications do not need to compute hashes • Keys that change monotonically like ObjectId or timestamps are ideal © 2017 Pythian. Confidential
  • 28. Shard keys limitations • Must be ascending indexed key or indexed compound keys that exists in every document in the collection • Cannot be multikey index, a text index or a geospatial index • Cannot exceed 512 bytes • Immutable key - can not be updated/changed • Update operations that affect a single document must include the shard key or the _id field • No option for sharding if unique indexes on other fields exist • No option for second unique index if the shard key is unique index © 2017 Pythian. Confidential
  • 29. Summary • Replica set with odd number of voting members • Hidden or Delayed member for dedicated functions (backups …) • Dataset fits into single server, keep unsharded deployment • Horizontal scaling - shards running as replica sets • Shard keys are immutable with max size of 512 bytes • Shard keys must exists in every document in the collection • Ranged sharding may not distribute the data evenly • Hashed sharding distributes the data randomly © 2017 Pythian. Confidential