SlideShare a Scribd company logo
Sharding
Jared Rosoff (@forjared)
Overview
• Architecture
• How it works
• Use Cases
SHARDING
ARCHITECTURE
Architecture
                             Shards

           mongod      mongod             mongod
                                                               ...
           mongod      mongod             mongod

           mongod      mongod             mongod
 Config
 Servers

mongod
                       mongos           mongos           ...
mongod

mongod
                    client    client   client   client
mongos
                                                                     • Shard Router
                             Shards
                                                                     • Acts just like a MongoD
           mongod      mongod             mongod

           mongod      mongod             mongod
                                                               ...
                                                                     • 1 or as many as you
 Config
           mongod      mongod             mongod                       want
 Servers

mongod
                                                                     • Can run on App
mongod
                       mongos           mongos           ...
                                                                       Servers
                                                                     • Caches meta-data from
mongod
                    client    client   client   client

                                                                       config servers
Config Server
                                                                     • 3 of them
                             Shards
                                                                     • Changes use 2 phase
           mongod      mongod             mongod

           mongod      mongod             mongod
                                                               ...     commit
 Config
           mongod      mongod             mongod                     • If any are down, meta
 Servers

mongod
                                                                       data goes read only
mongod
                       mongos           mongos           ...
                                                                     • System is online as
mongod
                    client    client   client   client
                                                                       long as 1/3 is up
HOW IT WORKS
Keys
> db.runCommand( { shardcollection: “test.users”,
                   key: { email: 1 }} )



      {
          name: “Jared”,
          email: “jsr@10gen.com”,
      }
      {
          name: “Scott”,
          email: “scott@10gen.com”,
      }
      {
          name: “Dan”,
          email: “dan@10gen.com”,
      }
Chunks


-∞            +
              ∞
Chunks


-∞                                              +
                                                ∞


     dan@10gen.com            scott@10gen.com

              jsr@10gen.com
Chunks
                     Split!



-∞                                              +
                                                ∞


     dan@10gen.com            scott@10gen.com

              jsr@10gen.com
Chunks
     This is a              Split!         This is a
      chunk                                 chunk


-∞                                                     +
                                                       ∞


            dan@10gen.com            scott@10gen.com

                     jsr@10gen.com
Chunks


-∞                                              +
                                                ∞


     dan@10gen.com            scott@10gen.com

              jsr@10gen.com
Chunks


-∞                                              +
                                                ∞


     dan@10gen.com            scott@10gen.com

              jsr@10gen.com
Chunks
     Split!



-∞                                              +
                                                ∞


     dan@10gen.com            scott@10gen.com

              jsr@10gen.com
Chunks
Min Key           Max Key           Shard
-∞                adam@10gen.com    1
adam@10gen.com    jared@10gen.com   1
jared@10gen.com   scott@10gen.com   1
scott@10gen.com   +∞                1


• Stored in the config servers
• Cached in MongoS
• Used to route requests and keep cluster
  balanced
Balancing
                                      mongos
                                                                                  config
                                      balancer
                                                                                  config
Chunks!
                                                                                  config




  1    2    3    4    13    14   15   16         25    26   27   28   37    38   39   40

  5    6    7    8    17    18   19   20         29    30   31   32   41    42   43   44

  9    10   11   12   21    22   23   24         33    34   35   36   45    46   47   48


      Shard 1              Shard 2                    Shard 3              Shard 4
Balancing
                                      mongos
                                                                                  config
                                      balancer
                                                                                  config

                    Imbalance
                     Imbalance                                                    config




1    2    3    4

5    6    7    8

9    10   11   12     21    22   23   24         33    34   35   36   45    46   47   48


    Shard 1                Shard 2                    Shard 3              Shard 4
Balancing
                                     mongos
                                                                                 config
                                     balancer
                                                                                 config

                               Move chunk 1                                      config
                               to Shard 2




1    2    3    4

5    6    7    8

9    10   11   12   21    22    23   24         33    34   35   36   45    46   47   48


    Shard 1              Shard 2                     Shard 3              Shard 4
Balancing
                                    mongos
                                                                                config
                                    balancer
                                                                                config

                                                                                config




1    2    3    4

5    6    7    8

9    10   11   12   21    22   23   24         33    34   35   36   45    46   47   48


    Shard 1              Shard 2                    Shard 3              Shard 4
Balancing
                                    mongos
                                                                                config
                                    balancer
                                                                                config
                                         Chunk 1 now lives
                                            on Shard 2                          config




     2    3    4

5    6    7    8    1

9    10   11   12   21    22   23   24         33    34   35   36   45    46   47   48


    Shard 1              Shard 2                    Shard 3              Shard 4
ROUTING
Routed Request
                         1

                                        1. Query arrives at
                          4
                     mongos                MongoS
                                        2. MongoS routes query
                                           to a single shard
                                        3. Shard returns results
                                           of query
                     2
                                        4. Results returned to
                                           client
                     3




Shard 1    Shard 2            Shard 3
Scatter Gather
                            1

                             4                 1. Query arrives at
                        mongos                    MongoS
                                               2. MongoS broadcasts
                                                  query to all shards
                                               3. Each shard returns
                                                  results for query
          2                                    4. Results combined
                    2            2                and returned to client
                                      3
          3             3



Shard 1       Shard 2                Shard 3
Distributed Merge Sort
                            1

                             6                1. Query arrives at
                        mongos                   MongoS
                                              2. MongoS broadcasts
                            5
                                                 query to all shards
                                              3. Each shard locally
                                                 sorts results
          2                                   4. Results returned to
                    2           2                mongos
          4             4            4        5. MongoS merge sorts
                                                 individual results
3                                             6. Combined sorted
              3                           3
                                                 result returned to
Shard 1       Shard 2               Shard 3      client
Writes

Inserts   Requires shard   db.users.insert({
          key                name: “Jared”,
                             email: “jsr@10gen.com”})
Removes   Routed           db.users.delete({
                             email: “jsr@10gen.com”})
          Scattered        db.users.delete({name: “Jared”})
Updates   Routed           db.users.update(
                             {email: “jsr@10gen.com”},
                             {$set: { state: “CA”}})
          Scattered        db.users.update(
                             {state: “FZ”},
                             {$set:{ state: “CA”}} )
Queries

By Shard      Routed            db.users.find(
                                  {email: “jsr@10gen.com”})
Key
Sorted by     Routed in order   db.users.find().sort({email:-1})
shard key
Find by non   Scatter Gather    db.users.find({state:”CA”})
shard key
Sorted by     Distributed       db.users.find().sort({state:1})
              merge sort
non shard
key
EXAMPLES
User Profiles
{
                              • Shard by email
    name: “Jared”,
    email: “jsr@10gen.com”,   • Lookup by email hits
    addresses: [                1 node
      {state: “CA”}
    ]                         • Index on
}                               {“addresses.state”:1}
Activity Stream
{
                                • Shard by user_id
    user_id: “jsr@10gen.com”,
    event_id: “Logged in”,      • Looking up a stream
    data: “…”                     hits 1 node
}
                                • Writing is evenly
                                  distributed
                                • Index on {“event_id”:1}
                                  for deletes
Photos
{
                         • What’s the right key?
    photo_id: ???,
    data: BinData(…)       –   Auto Increment?
}                          –   MD5( data )
                           –   Now() + MD5(data)
                           –   Month() + MD5(data)
Mongosv 2011 - Sharding

More Related Content

Similar to Mongosv 2011 - Sharding

Struds overview
Struds overviewStruds overview
Struds overview
Sreedinesh Sridharan
 
Firefox3.5 And Next
Firefox3.5 And NextFirefox3.5 And Next
Firefox3.5 And NextChanny Yun
 
Style Guide Package
Style Guide PackageStyle Guide Package
Style Guide Package4Ward
 
The science behind breaking world records
The science behind breaking world recordsThe science behind breaking world records
The science behind breaking world records
gwfestival
 
Web design annual plan annual plan
Web design annual plan annual planWeb design annual plan annual plan
Web design annual plan annual plancal1968
 
『Ficia』インフラとPerlにまつわるエトセトラ
『Ficia』インフラとPerlにまつわるエトセトラ『Ficia』インフラとPerlにまつわるエトセトラ
『Ficia』インフラとPerlにまつわるエトセトラMasaaki HIROSE
 
Business Startup Package
Business Startup PackageBusiness Startup Package
Business Startup Package4Ward
 
From java to rails
From java to railsFrom java to rails
From java to railsjokry
 
Business Corporate Pack
Business Corporate PackBusiness Corporate Pack
Business Corporate Pack4Ward
 
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the CloudWebinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Internap
 
Intro to Table-Grouping™ technology
Intro to Table-Grouping™ technologyIntro to Table-Grouping™ technology
Intro to Table-Grouping™ technology
David McFarlane
 
クックパッドでのemr利用事例
クックパッドでのemr利用事例クックパッドでのemr利用事例
クックパッドでのemr利用事例
Tatsuya Sasaki
 
iOS Architecture and MVC
iOS Architecture and MVCiOS Architecture and MVC
iOS Architecture and MVC
Marian Ignev
 
Using Database Constraints Wisely
Using Database Constraints WiselyUsing Database Constraints Wisely
Using Database Constraints Wisely
barunio
 
OSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business ProcessesOSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business Processes
Eric D. Schabell
 
RIPE Atlas
RIPE AtlasRIPE Atlas
RIPE Atlas
RIPE NCC
 
Introduction to Clojure's STM
Introduction to Clojure's STMIntroduction to Clojure's STM
Introduction to Clojure's STMFronx Wurmus
 
Making a commercial success of new products and services dec 11
Making a commercial success of new products and services dec 11Making a commercial success of new products and services dec 11
Making a commercial success of new products and services dec 11
Paul Fileman
 
The Application Development Landscape - 2011
The Application Development Landscape -  2011The Application Development Landscape -  2011
The Application Development Landscape - 2011
David Skok
 
Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...
Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...
Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...
Kara Van Malssen
 

Similar to Mongosv 2011 - Sharding (20)

Struds overview
Struds overviewStruds overview
Struds overview
 
Firefox3.5 And Next
Firefox3.5 And NextFirefox3.5 And Next
Firefox3.5 And Next
 
Style Guide Package
Style Guide PackageStyle Guide Package
Style Guide Package
 
The science behind breaking world records
The science behind breaking world recordsThe science behind breaking world records
The science behind breaking world records
 
Web design annual plan annual plan
Web design annual plan annual planWeb design annual plan annual plan
Web design annual plan annual plan
 
『Ficia』インフラとPerlにまつわるエトセトラ
『Ficia』インフラとPerlにまつわるエトセトラ『Ficia』インフラとPerlにまつわるエトセトラ
『Ficia』インフラとPerlにまつわるエトセトラ
 
Business Startup Package
Business Startup PackageBusiness Startup Package
Business Startup Package
 
From java to rails
From java to railsFrom java to rails
From java to rails
 
Business Corporate Pack
Business Corporate PackBusiness Corporate Pack
Business Corporate Pack
 
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the CloudWebinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
Webinar: Top 5 Mistakes Your Don't Want to Make When Moving to the Cloud
 
Intro to Table-Grouping™ technology
Intro to Table-Grouping™ technologyIntro to Table-Grouping™ technology
Intro to Table-Grouping™ technology
 
クックパッドでのemr利用事例
クックパッドでのemr利用事例クックパッドでのemr利用事例
クックパッドでのemr利用事例
 
iOS Architecture and MVC
iOS Architecture and MVCiOS Architecture and MVC
iOS Architecture and MVC
 
Using Database Constraints Wisely
Using Database Constraints WiselyUsing Database Constraints Wisely
Using Database Constraints Wisely
 
OSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business ProcessesOSC11 - The future is now for all your Business Processes
OSC11 - The future is now for all your Business Processes
 
RIPE Atlas
RIPE AtlasRIPE Atlas
RIPE Atlas
 
Introduction to Clojure's STM
Introduction to Clojure's STMIntroduction to Clojure's STM
Introduction to Clojure's STM
 
Making a commercial success of new products and services dec 11
Making a commercial success of new products and services dec 11Making a commercial success of new products and services dec 11
Making a commercial success of new products and services dec 11
 
The Application Development Landscape - 2011
The Application Development Landscape -  2011The Application Development Landscape -  2011
The Application Development Landscape - 2011
 
Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...
Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...
Implementing Metadata Standards for a Digital Audiovisual Preservation Reposi...
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

Mongosv 2011 - Sharding

  • 2. Overview • Architecture • How it works • Use Cases
  • 4. Architecture Shards mongod mongod mongod ... mongod mongod mongod mongod mongod mongod Config Servers mongod mongos mongos ... mongod mongod client client client client
  • 5. mongos • Shard Router Shards • Acts just like a MongoD mongod mongod mongod mongod mongod mongod ... • 1 or as many as you Config mongod mongod mongod want Servers mongod • Can run on App mongod mongos mongos ... Servers • Caches meta-data from mongod client client client client config servers
  • 6. Config Server • 3 of them Shards • Changes use 2 phase mongod mongod mongod mongod mongod mongod ... commit Config mongod mongod mongod • If any are down, meta Servers mongod data goes read only mongod mongos mongos ... • System is online as mongod client client client client long as 1/3 is up
  • 8. Keys > db.runCommand( { shardcollection: “test.users”, key: { email: 1 }} ) { name: “Jared”, email: “jsr@10gen.com”, } { name: “Scott”, email: “scott@10gen.com”, } { name: “Dan”, email: “dan@10gen.com”, }
  • 9. Chunks -∞ + ∞
  • 10. Chunks -∞ + ∞ dan@10gen.com scott@10gen.com jsr@10gen.com
  • 11. Chunks Split! -∞ + ∞ dan@10gen.com scott@10gen.com jsr@10gen.com
  • 12. Chunks This is a Split! This is a chunk chunk -∞ + ∞ dan@10gen.com scott@10gen.com jsr@10gen.com
  • 13. Chunks -∞ + ∞ dan@10gen.com scott@10gen.com jsr@10gen.com
  • 14. Chunks -∞ + ∞ dan@10gen.com scott@10gen.com jsr@10gen.com
  • 15. Chunks Split! -∞ + ∞ dan@10gen.com scott@10gen.com jsr@10gen.com
  • 16. Chunks Min Key Max Key Shard -∞ adam@10gen.com 1 adam@10gen.com jared@10gen.com 1 jared@10gen.com scott@10gen.com 1 scott@10gen.com +∞ 1 • Stored in the config servers • Cached in MongoS • Used to route requests and keep cluster balanced
  • 17. Balancing mongos config balancer config Chunks! config 1 2 3 4 13 14 15 16 25 26 27 28 37 38 39 40 5 6 7 8 17 18 19 20 29 30 31 32 41 42 43 44 9 10 11 12 21 22 23 24 33 34 35 36 45 46 47 48 Shard 1 Shard 2 Shard 3 Shard 4
  • 18. Balancing mongos config balancer config Imbalance Imbalance config 1 2 3 4 5 6 7 8 9 10 11 12 21 22 23 24 33 34 35 36 45 46 47 48 Shard 1 Shard 2 Shard 3 Shard 4
  • 19. Balancing mongos config balancer config Move chunk 1 config to Shard 2 1 2 3 4 5 6 7 8 9 10 11 12 21 22 23 24 33 34 35 36 45 46 47 48 Shard 1 Shard 2 Shard 3 Shard 4
  • 20. Balancing mongos config balancer config config 1 2 3 4 5 6 7 8 9 10 11 12 21 22 23 24 33 34 35 36 45 46 47 48 Shard 1 Shard 2 Shard 3 Shard 4
  • 21. Balancing mongos config balancer config Chunk 1 now lives on Shard 2 config 2 3 4 5 6 7 8 1 9 10 11 12 21 22 23 24 33 34 35 36 45 46 47 48 Shard 1 Shard 2 Shard 3 Shard 4
  • 23. Routed Request 1 1. Query arrives at 4 mongos MongoS 2. MongoS routes query to a single shard 3. Shard returns results of query 2 4. Results returned to client 3 Shard 1 Shard 2 Shard 3
  • 24. Scatter Gather 1 4 1. Query arrives at mongos MongoS 2. MongoS broadcasts query to all shards 3. Each shard returns results for query 2 4. Results combined 2 2 and returned to client 3 3 3 Shard 1 Shard 2 Shard 3
  • 25. Distributed Merge Sort 1 6 1. Query arrives at mongos MongoS 2. MongoS broadcasts 5 query to all shards 3. Each shard locally sorts results 2 4. Results returned to 2 2 mongos 4 4 4 5. MongoS merge sorts individual results 3 6. Combined sorted 3 3 result returned to Shard 1 Shard 2 Shard 3 client
  • 26. Writes Inserts Requires shard db.users.insert({ key name: “Jared”, email: “jsr@10gen.com”}) Removes Routed db.users.delete({ email: “jsr@10gen.com”}) Scattered db.users.delete({name: “Jared”}) Updates Routed db.users.update( {email: “jsr@10gen.com”}, {$set: { state: “CA”}}) Scattered db.users.update( {state: “FZ”}, {$set:{ state: “CA”}} )
  • 27. Queries By Shard Routed db.users.find( {email: “jsr@10gen.com”}) Key Sorted by Routed in order db.users.find().sort({email:-1}) shard key Find by non Scatter Gather db.users.find({state:”CA”}) shard key Sorted by Distributed db.users.find().sort({state:1}) merge sort non shard key
  • 29. User Profiles { • Shard by email name: “Jared”, email: “jsr@10gen.com”, • Lookup by email hits addresses: [ 1 node {state: “CA”} ] • Index on } {“addresses.state”:1}
  • 30. Activity Stream { • Shard by user_id user_id: “jsr@10gen.com”, event_id: “Logged in”, • Looking up a stream data: “…” hits 1 node } • Writing is evenly distributed • Index on {“event_id”:1} for deletes
  • 31. Photos { • What’s the right key? photo_id: ???, data: BinData(…) – Auto Increment? } – MD5( data ) – Now() + MD5(data) – Month() + MD5(data)