SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Mongodb Sharding
    by Fan, Xiangrong




            1
Agenda
• Why Sharding
• Sharding Architecture
• What is Sharding
• Sharding Balancer
• Write/Reads with Sharding
• Sharding Limitation
• Demo              2
Why Sharding
• All writes go to master
• Latency sensitive queries still go to master
• Single replica set has limitation of 12 nodes
• Memory can’t be large enough when active
  dataset is big
• Local Disk is not big enough
• Vertical upgrade is too expensive
                       3
Architecture
Config

         Config Servers
                                              Servers

                                              mongod

                                              mongod
• We have three config servers in prod
  cluster or one in test environment          mongod

• Changes are made using 2 phase commit to
  provide strong consistency among all 3
  config servers
• If anyone is down, meta data will be read
  only
• System is online as long as 1/3 is up
                       5
shard1
                Shards                mongo

                                      mongo


• Each Shard can be master, master/slave or
  replica set
• Replica set provides auto-failover capability
  for sharding cluster
• Regular mongod processes

                         6
Mongos
                                        mongos


• Sharding Router
• Acts just like a mongod to clients, it makes
  the cluster “invisible” to clients
• You can have as many as you want
• It’s suggested to run on appserver
• It caches metadata from config servers
                        7
Mongos

 Mongod




  Clients




     8
What is Sharding
•   It’s range based

•   Automatic balancing for changes in load and data distribution

•   Convert from single replica set to sharding cluster without
    downtime

•   Easy addition of new shards without downtime

•   Scaling to one thousand nodes

•   No single points of failure

•   Automatic failover



                                  9
Shard key
•   It can be one or more fields

•   every document needs a shard key (null is ok)

•   shard key can’t be updated

•   MongoDB's sharding is order-preserving.You can
    define the shard key as ascending order or
    descending order, like { tag : 1, timestamp : -1 }

•   null < numbers < strings < objects < arrays <
    binary data < ObjectIds < booleans < dates <
    regular expressions

                           10
Chunk
•   A chunk is a contiguous range of data from a
    particular collection

•   Collection is broken into chunks by range

•   A chunk is a logical concept, not a physical
    reality. $minKey <= key < $maxKey

•   Each document must belong to one and only
    one chunk

•   default size is 64M, can be specified by --
    chunksize
                          11
Chunk




  12
Chunk Split

• When chunk reaches its size limit, split
  happens
• Split is an inexpensive metadata operation
• You can manually split chunks

                      13
Chunk Split




    14
Chunk Split


   (-∞, +∞ )




    14
Chunk Split


(-∞, 0)        [0, +∞ )




          14
Chunk Split


(-∞, -500)   [-500, 0)        [0, +∞ )




                         14
Chunk Split


(-∞, -500)   [-500, 0)        [0, 500)   [500, +∞)




                         14
Chunk Migration
• Chunk Migration is an expensive operation
• Only one chunk migration happens at any
  time
• based on overall size of the shard
• Balancer will automatically migrate chunks
  between shards
• you can also manually move chunks
                     15
Sharding Balancer
• keep data evenly distributed on all shards
• minimize the amount of data transfered
• For a balancing round to occur, a shard
  must have at least nine more chunks than
  the least-populous shard
• it can be turn off
  •   db.settings.update({"_id" : "balancer"}, {"$set" : {"stopped" : true }}, true)


                                       16
Sharding Balancer

mongod   mongod   mongod    mongod   mongod   mongod   mongod




                      mongos




                           17
Sharding Balancer

mongod            mongod    mongod   mongod   mongod   mongod

         mongod




                      mongos




                           17
Sharding Balancer

mongod            mongod    mongod   mongod   mongod   mongod
         mongod




                      mongos




                           18
Sharding Balancer

mongod   mongod   mongod    mongod   mongod   mongod   mongod




                      mongos




                           19
Choosing Shard Key
• A good shard key can distribute reads and
  writes, but that also keeps the data you’re
  using together
• Don’t use ascending shard key like ID
• Don’t use low cardinality shard key like
  continent
• Don’t use random shard key like MD5
• Good example: Coarsely ascending key +
  search key
                      20
Reads/Writes with
    Sharding




        21
Sharding Limitation
•   Unique index can’t be created without shared
    key as a prefix

•   You can’t update shard key

•   Only one chunk move in the cluster at a time

•   Sharding does not yet support data center
    awareness

•   Add new shards brings in more traffic to
    existing cluster

•   20Pb size limit
                        22
Demo
• Startup Shards
• Startup config servers
• Startup mongos
• Configure Shards
• Shard Data
• Look at config data @ mongo config server
                   23
Startup Shards
• mkdir /data/db/a /data/db/b
• ./mongod --shardsvr --dbpath /data/db/a --
  port 10000 > /tmp/sharda.log &
• cat /tmp/sharda.log
• ./mongod --shardsvr --dbpath /data/db/b --
  port 10001 > /tmp/shardb.log &
• cat /tmp/shardb.log
                        24
Startup Config Server


• mkdir /data/db/config
• ./mongod --configsvr --dbpath /data/db/
  config --port 20000 > /tmp/configdb.log &
• cat /tmp/configdb.log

                    25
Startup Mongos


• ./mongos --configdb localhost:20000 > /
  tmp/mongos.log &
• cat /tmp/mongos.log


                     26
Config Shards
•   $ ./mongo
•   MongoDB shell version: 1.6.0
•   connecting to: test
•   > use admin
    •   switched to db admin
•   > db.runCommand( { addshard : "localhost:10000" } )
    •   { "shardadded" : "shard0000", "ok" : 1 }
•   > db.runCommand( { addshard : "localhost:10001" } )
    •   { "shardadded" : "shard0001", "ok" : 1 }


                                 27
Shard Data
• > db.runCommand( { enablesharding :
  "test" } )
   • {"ok" : 1}
• > db.runCommand( { shardcollection :
  "test.people", key : {name : 1} } )
   • {"ok" : 1}
                       28
Add Shards


• db.runCommand( { addshard : "foo/
  <serverhostname>[:<port>]" } ); {"ok" : 1 ,
  "added" : "foo"}




                     29
Look at config data

•   Login config database

•   db.shards.find()

•   db.databases.find()

•   db.chunks.find()

•   db.printShardingStatus(true)



                           30
Recommend Reads
• Mongodb Documentation
 • http://www.mongodb.org/display/DOCS/
    Sharding
• Book “Scaling Mongodb”
 • You can find it on
    www.safaribooksonline.com


                   31
Q &A



  32

Weitere ähnliche Inhalte

Was ist angesagt?

Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDBMongoDB
 
Sharding
ShardingSharding
ShardingMongoDB
 
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB
 
I have a good shard key now what - Advanced Sharding
I have a good shard key now what - Advanced ShardingI have a good shard key now what - Advanced Sharding
I have a good shard key now what - Advanced ShardingDavid Murphy
 
Lightning Talk: MongoDB Sharding
Lightning Talk: MongoDB ShardingLightning Talk: MongoDB Sharding
Lightning Talk: MongoDB ShardingMongoDB
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performanceDaum DNA
 
Everything You Need to Know About Sharding
Everything You Need to Know About ShardingEverything You Need to Know About Sharding
Everything You Need to Know About ShardingMongoDB
 
MongoDB Deployment Checklist
MongoDB Deployment ChecklistMongoDB Deployment Checklist
MongoDB Deployment ChecklistMongoDB
 
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 Capacity Planning
MongoDB Capacity PlanningMongoDB Capacity Planning
MongoDB Capacity PlanningNorberto Leite
 
Sharding
ShardingSharding
ShardingMongoDB
 
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 MinutesLightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 MinutesMongoDB
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersSeveralnines
 
Back to Basics 2017: Introduction to Sharding
Back to Basics 2017: Introduction to ShardingBack to Basics 2017: Introduction to Sharding
Back to Basics 2017: Introduction to ShardingMongoDB
 
Webinar: When to Use MongoDB
Webinar: When to Use MongoDBWebinar: When to Use MongoDB
Webinar: When to Use MongoDBMongoDB
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDBRick Copeland
 
Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101MongoDB
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB
 
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops TeamEvolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops TeamMydbops
 

Was ist angesagt? (20)

Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
 
Sharding
ShardingSharding
Sharding
 
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo SeattleMongoDB Auto-Sharding at Mongo Seattle
MongoDB Auto-Sharding at Mongo Seattle
 
MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals MongoDB Sharding Fundamentals
MongoDB Sharding Fundamentals
 
I have a good shard key now what - Advanced Sharding
I have a good shard key now what - Advanced ShardingI have a good shard key now what - Advanced Sharding
I have a good shard key now what - Advanced Sharding
 
Lightning Talk: MongoDB Sharding
Lightning Talk: MongoDB ShardingLightning Talk: MongoDB Sharding
Lightning Talk: MongoDB Sharding
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performance
 
Everything You Need to Know About Sharding
Everything You Need to Know About ShardingEverything You Need to Know About Sharding
Everything You Need to Know About Sharding
 
MongoDB Deployment Checklist
MongoDB Deployment ChecklistMongoDB Deployment Checklist
MongoDB Deployment Checklist
 
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 Capacity Planning
MongoDB Capacity PlanningMongoDB Capacity Planning
MongoDB Capacity Planning
 
Sharding
ShardingSharding
Sharding
 
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 MinutesLightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB Clusters
 
Back to Basics 2017: Introduction to Sharding
Back to Basics 2017: Introduction to ShardingBack to Basics 2017: Introduction to Sharding
Back to Basics 2017: Introduction to Sharding
 
Webinar: When to Use MongoDB
Webinar: When to Use MongoDBWebinar: When to Use MongoDB
Webinar: When to Use MongoDB
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
 
Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: Sharding
 
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops TeamEvolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
 

Ähnlich wie Mongodb sharding

Sharding
ShardingSharding
ShardingMongoDB
 
2011 mongo sf-scaling
2011 mongo sf-scaling2011 mongo sf-scaling
2011 mongo sf-scalingMongoDB
 
Sharding
ShardingSharding
ShardingMongoDB
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)MongoDB
 
Scaling MongoDB (Mongo Austin)
Scaling MongoDB (Mongo Austin)Scaling MongoDB (Mongo Austin)
Scaling MongoDB (Mongo Austin)MongoDB
 
Sharding - Seoul 2012
Sharding - Seoul 2012Sharding - Seoul 2012
Sharding - Seoul 2012MongoDB
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to ShardingMongoDB
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceSasidhar Gogulapati
 
2014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-22014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-2MongoDB
 
Sharding Overview
Sharding OverviewSharding Overview
Sharding OverviewMongoDB
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDBMongoDB
 
Cassandra tech talk
Cassandra tech talkCassandra tech talk
Cassandra tech talkSatish Mehta
 
Webinar: Sharding
Webinar: ShardingWebinar: Sharding
Webinar: ShardingMongoDB
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDBMongoDB
 
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
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment StrategiesMongoDB
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Chris Richardson
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Consjohnrjenson
 

Ähnlich wie Mongodb sharding (20)

Sharding
ShardingSharding
Sharding
 
2011 mongo sf-scaling
2011 mongo sf-scaling2011 mongo sf-scaling
2011 mongo sf-scaling
 
Sharding
ShardingSharding
Sharding
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)
 
Scaling MongoDB (Mongo Austin)
Scaling MongoDB (Mongo Austin)Scaling MongoDB (Mongo Austin)
Scaling MongoDB (Mongo Austin)
 
Sharding - Seoul 2012
Sharding - Seoul 2012Sharding - Seoul 2012
Sharding - Seoul 2012
 
Introduction to Sharding
Introduction to ShardingIntroduction to Sharding
Introduction to Sharding
 
MongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & PerformanceMongoDB : Scaling, Security & Performance
MongoDB : Scaling, Security & Performance
 
2014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-22014 05-07-fr - add dev series - session 6 - deploying your application-2
2014 05-07-fr - add dev series - session 6 - deploying your application-2
 
Sharding Overview
Sharding OverviewSharding Overview
Sharding Overview
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
 
Cassandra tech talk
Cassandra tech talkCassandra tech talk
Cassandra tech talk
 
Webinar: Sharding
Webinar: ShardingWebinar: Sharding
Webinar: Sharding
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with 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 Cluster
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Deployment
DeploymentDeployment
Deployment
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 

Kürzlich hochgeladen

Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...call girls kolkata
 
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and ModelMandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Modelhotbabesbook
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Pakistani Call girls in Ajman 0505086370 Ajman Call girls
Pakistani Call girls in Ajman 0505086370 Ajman Call girlsPakistani Call girls in Ajman 0505086370 Ajman Call girls
Pakistani Call girls in Ajman 0505086370 Ajman Call girlsMonica Sydney
 
Satara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort serviceSatara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort serviceNitya salvi
 
Gonda Nitya salvi 8617370543 VIP model college girls ...
Gonda Nitya salvi 8617370543 VIP model college girls ...Gonda Nitya salvi 8617370543 VIP model college girls ...
Gonda Nitya salvi 8617370543 VIP model college girls ...Nitya salvi
 
Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...
Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...
Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...priyasharma62062
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsMonica Sydney
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyNitya salvi
 
Deira Call girl 0506129535 Independent Call girl in Deira
Deira Call girl 0506129535  Independent Call girl in DeiraDeira Call girl 0506129535  Independent Call girl in Deira
Deira Call girl 0506129535 Independent Call girl in DeiraMonica Sydney
 
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyHire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyNitya salvi
 
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...Call Girls Mumbai
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...Priya Reddy
 
Deira call girls 0507330913 Call girls in Deira
Deira call girls 0507330913  Call girls in DeiraDeira call girls 0507330913  Call girls in Deira
Deira call girls 0507330913 Call girls in DeiraMonica Sydney
 
Deira Call girls Service 0507330913 Call girls in Deira
Deira Call girls Service 0507330913  Call girls in DeiraDeira Call girls Service 0507330913  Call girls in Deira
Deira Call girls Service 0507330913 Call girls in DeiraMonica Sydney
 
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...DipikaDelhi
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Nitya salvi
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableNitya salvi
 
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...call girls kolkata
 
Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...
Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...
Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...kumargunjan9515
 

Kürzlich hochgeladen (20)

Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
 
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and ModelMandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
 
Pakistani Call girls in Ajman 0505086370 Ajman Call girls
Pakistani Call girls in Ajman 0505086370 Ajman Call girlsPakistani Call girls in Ajman 0505086370 Ajman Call girls
Pakistani Call girls in Ajman 0505086370 Ajman Call girls
 
Satara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort serviceSatara call girl 8617370543♥️ call girls in satara escort service
Satara call girl 8617370543♥️ call girls in satara escort service
 
Gonda Nitya salvi 8617370543 VIP model college girls ...
Gonda Nitya salvi 8617370543 VIP model college girls ...Gonda Nitya salvi 8617370543 VIP model college girls ...
Gonda Nitya salvi 8617370543 VIP model college girls ...
 
Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...
Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...
Thane Female Escorts-✔9833754194-Kalyan Reasonalble Escorts-Kurla Independent...
 
Pakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girlsPakistani Call girls in Deira 0567006274 Deira Call girls
Pakistani Call girls in Deira 0567006274 Deira Call girls
 
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls AgencyHire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
Hire 💕 8617370543 Mirzapur Call Girls Service Call Girls Agency
 
Deira Call girl 0506129535 Independent Call girl in Deira
Deira Call girl 0506129535  Independent Call girl in DeiraDeira Call girl 0506129535  Independent Call girl in Deira
Deira Call girl 0506129535 Independent Call girl in Deira
 
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls AgencyHire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
Hire 💕 8617370543 Kushinagar Call Girls Service Call Girls Agency
 
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
Bhubaneswar🌹Patia ❤CALL GIRLS 9777949614 💟 CALL GIRLS IN bhubaneswar ESCORT S...
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
 
Deira call girls 0507330913 Call girls in Deira
Deira call girls 0507330913  Call girls in DeiraDeira call girls 0507330913  Call girls in Deira
Deira call girls 0507330913 Call girls in Deira
 
Deira Call girls Service 0507330913 Call girls in Deira
Deira Call girls Service 0507330913  Call girls in DeiraDeira Call girls Service 0507330913  Call girls in Deira
Deira Call girls Service 0507330913 Call girls in Deira
 
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
Call girls Service Berhampur - 9332606886 Our call girls are sure to provide ...
 
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
Call Girls In Gorakhpur Escorts ☎️8617370543 🔝 💃 Enjoy 24/7 Escort Service En...
 
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Moradabad Just Call 8617370543 Top Class Call Girl Service Available
 
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
Call Girls in Kollam - 9332606886 Our call girls are sure to provide you with...
 
Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...
Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...
Call Girls in Nizampet / 8250092165 Genuine Call girls with real Photos and N...
 

Mongodb sharding

  • 1. Mongodb Sharding by Fan, Xiangrong 1
  • 2. Agenda • Why Sharding • Sharding Architecture • What is Sharding • Sharding Balancer • Write/Reads with Sharding • Sharding Limitation • Demo 2
  • 3. Why Sharding • All writes go to master • Latency sensitive queries still go to master • Single replica set has limitation of 12 nodes • Memory can’t be large enough when active dataset is big • Local Disk is not big enough • Vertical upgrade is too expensive 3
  • 5. Config Config Servers Servers mongod mongod • We have three config servers in prod cluster or one in test environment mongod • Changes are made using 2 phase commit to provide strong consistency among all 3 config servers • If anyone is down, meta data will be read only • System is online as long as 1/3 is up 5
  • 6. shard1 Shards mongo mongo • Each Shard can be master, master/slave or replica set • Replica set provides auto-failover capability for sharding cluster • Regular mongod processes 6
  • 7. Mongos mongos • Sharding Router • Acts just like a mongod to clients, it makes the cluster “invisible” to clients • You can have as many as you want • It’s suggested to run on appserver • It caches metadata from config servers 7
  • 8. Mongos Mongod Clients 8
  • 9. What is Sharding • It’s range based • Automatic balancing for changes in load and data distribution • Convert from single replica set to sharding cluster without downtime • Easy addition of new shards without downtime • Scaling to one thousand nodes • No single points of failure • Automatic failover 9
  • 10. Shard key • It can be one or more fields • every document needs a shard key (null is ok) • shard key can’t be updated • MongoDB's sharding is order-preserving.You can define the shard key as ascending order or descending order, like { tag : 1, timestamp : -1 } • null < numbers < strings < objects < arrays < binary data < ObjectIds < booleans < dates < regular expressions 10
  • 11. Chunk • A chunk is a contiguous range of data from a particular collection • Collection is broken into chunks by range • A chunk is a logical concept, not a physical reality. $minKey <= key < $maxKey • Each document must belong to one and only one chunk • default size is 64M, can be specified by -- chunksize 11
  • 13. Chunk Split • When chunk reaches its size limit, split happens • Split is an inexpensive metadata operation • You can manually split chunks 13
  • 15. Chunk Split (-∞, +∞ ) 14
  • 16. Chunk Split (-∞, 0) [0, +∞ ) 14
  • 17. Chunk Split (-∞, -500) [-500, 0) [0, +∞ ) 14
  • 18. Chunk Split (-∞, -500) [-500, 0) [0, 500) [500, +∞) 14
  • 19. Chunk Migration • Chunk Migration is an expensive operation • Only one chunk migration happens at any time • based on overall size of the shard • Balancer will automatically migrate chunks between shards • you can also manually move chunks 15
  • 20. Sharding Balancer • keep data evenly distributed on all shards • minimize the amount of data transfered • For a balancing round to occur, a shard must have at least nine more chunks than the least-populous shard • it can be turn off • db.settings.update({"_id" : "balancer"}, {"$set" : {"stopped" : true }}, true) 16
  • 21. Sharding Balancer mongod mongod mongod mongod mongod mongod mongod mongos 17
  • 22. Sharding Balancer mongod mongod mongod mongod mongod mongod mongod mongos 17
  • 23. Sharding Balancer mongod mongod mongod mongod mongod mongod mongod mongos 18
  • 24. Sharding Balancer mongod mongod mongod mongod mongod mongod mongod mongos 19
  • 25. Choosing Shard Key • A good shard key can distribute reads and writes, but that also keeps the data you’re using together • Don’t use ascending shard key like ID • Don’t use low cardinality shard key like continent • Don’t use random shard key like MD5 • Good example: Coarsely ascending key + search key 20
  • 26. Reads/Writes with Sharding 21
  • 27. Sharding Limitation • Unique index can’t be created without shared key as a prefix • You can’t update shard key • Only one chunk move in the cluster at a time • Sharding does not yet support data center awareness • Add new shards brings in more traffic to existing cluster • 20Pb size limit 22
  • 28. Demo • Startup Shards • Startup config servers • Startup mongos • Configure Shards • Shard Data • Look at config data @ mongo config server 23
  • 29. Startup Shards • mkdir /data/db/a /data/db/b • ./mongod --shardsvr --dbpath /data/db/a -- port 10000 > /tmp/sharda.log & • cat /tmp/sharda.log • ./mongod --shardsvr --dbpath /data/db/b -- port 10001 > /tmp/shardb.log & • cat /tmp/shardb.log 24
  • 30. Startup Config Server • mkdir /data/db/config • ./mongod --configsvr --dbpath /data/db/ config --port 20000 > /tmp/configdb.log & • cat /tmp/configdb.log 25
  • 31. Startup Mongos • ./mongos --configdb localhost:20000 > / tmp/mongos.log & • cat /tmp/mongos.log 26
  • 32. Config Shards • $ ./mongo • MongoDB shell version: 1.6.0 • connecting to: test • > use admin • switched to db admin • > db.runCommand( { addshard : "localhost:10000" } ) • { "shardadded" : "shard0000", "ok" : 1 } • > db.runCommand( { addshard : "localhost:10001" } ) • { "shardadded" : "shard0001", "ok" : 1 } 27
  • 33. Shard Data • > db.runCommand( { enablesharding : "test" } ) • {"ok" : 1} • > db.runCommand( { shardcollection : "test.people", key : {name : 1} } ) • {"ok" : 1} 28
  • 34. Add Shards • db.runCommand( { addshard : "foo/ <serverhostname>[:<port>]" } ); {"ok" : 1 , "added" : "foo"} 29
  • 35. Look at config data • Login config database • db.shards.find() • db.databases.find() • db.chunks.find() • db.printShardingStatus(true) 30
  • 36. Recommend Reads • Mongodb Documentation • http://www.mongodb.org/display/DOCS/ Sharding • Book “Scaling Mongodb” • You can find it on www.safaribooksonline.com 31
  • 37. Q &A 32

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n