SlideShare a Scribd company logo
Mike	
  Dirolf	
  -­‐	
  @mdirolf	
  -­‐	
  10gen,	
  Inc.

                                            http://www.mongodb.org
Inside




  http://www.flickr.com/photos/tmh9/677919415/
a word of warning
  this	
  talk	
  might	
  be	
  a	
  bit	
  “hard”,
  but	
  MongoDB	
  is	
  really	
  easy:
  http://try.mongodb.org
db.test.insert({hello:	
  “world”})
_id

    if	
  not	
  specified	
  drivers	
  will	
  add	
  default:

ObjectId("4bface1a2231316e04f3c434")
                timestamp
                        machine	
  id
                               process	
  id
                                           counter


                  http://www.mongodb.org/display/DOCS/Object+IDs
BSON Encoding
     {_id:	
  ObjectId(XXXXXXXXXXXX),
     	
  hello:	
  “world”}


x27x00x00x00x07	
  	
  	
  _	
  	
  	
  i	
  	
  	
  dx00	
  	
  	
  X	
                                                     	
  
	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X	
  	
  	
  X
	
  	
  	
  Xx02	
  	
  	
  h	
  	
  	
  e	
  	
  	
  l	
  	
  	
  l	
  	
  	
  ox00x06x00
x00x00	
  	
  	
  w	
  	
  	
  o	
  	
  	
  r	
  	
  	
  l	
  	
  	
  dx00x00

                                                                                                      http://bsonspec.org
Insert Message (TCP/IP)

message	
  length   request	
  id                 response	
  id      op	
  code	
  (insert)
x68x00x00x00 xXXxXXxXXxXX x00x00x00x00 xd2x07x00x00

     reserved            collection	
  name                           document(s)
 x00x00x00x00      f	
  o	
  o	
  .	
  t	
  e	
  s	
  t	
  x00     BSON	
  Data




          http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
Data File Allocation

                           $	
  ls	
  -­‐sk	
  /data/db/

                                                           }
                           	
  16384	
  foo.ns             allocated	
  per	
  

(up	
  to	
  2	
  gigs){
double	
  in	
  size	
     	
  65536	
  foo.0
                           131072	
  foo.1
                                                             database


                           	
  16384	
  bar.ns
                           	
  	
  	
  	
  	
  	
  	
  ...
Memory Management
Extent Allocation
foo.0
                      allocated	
  per	
  namespace:
foo.1                      foo.test
        00000000000        foo.bar
                           foo.baz
        00000000000
        00000000000        foo.$freelist
        00000000000   0000 preallocated	
  space
foo.2   00000000000
        00000000000   ns	
  details	
  stored	
  in	
  foo.ns
        00000000000
        00000000000
Record Allocation
                      ...
  Header	
  (Size,	
  Offset,	
  Next,	
  Prev)
                BSON	
  Data
                   Padding

 Deleted	
  Record	
  (Size,	
  Offset,	
  Next)

                      ...
Indexing

B-­‐Tree	
  indexes,	
  stored	
  in	
  own	
  namespaces
                              >	
  db.system.namespaces.find()
                              {	
  "name"	
  :	
  "foo.system.indexes"	
  }
                              {	
  "name"	
  :	
  "foo.test"	
  }
                              {	
  "name"	
  :	
  "foo.test.$_id_"	
  }




                  http://www.mongodb.org/display/DOCS/Indexes
db.test.find({hello:	
  “world”})
Query Language

“query	
  by	
  example”	
  plus	
  $	
  modifiers:
 {first_name:	
  “Mike”,
 	
  age:	
  {$gte:	
  20,	
  $lt:	
  40}}




       http://www.mongodb.org/display/DOCS/Advanced+Queries
Cursors
>	
  var	
  c	
  =	
  db.test.find({x:	
  20}).skip(20).limit(10)
>	
  c.next()
>	
  c.next()
	
  	
  	
  ...
                                        query
                        first	
  N	
  results	
  +	
  cursor	
  id


                           getMore	
  w/	
  cursor	
  id
                    next	
  N	
  results	
  +	
  cursor	
  id	
  or	
  0
                                           ...
Query Optimizer
          find({x:	
  10,	
  y:	
  “foo”})


	
  	
  scan
                                    terminate
	
  	
  index	
  on	
  x

	
  	
  index	
  on	
  y     remember
db.foo.drop()
Commands


    drop,	
  count,	
  copydb,	
  
findAndModify,	
  serverStatus,	
  ...




         http://www.mongodb.org/display/DOCS/Commands
db.foo.drop();

                 =
  db.foo.runCommand({drop:	
  "foo"});

                 =
   db.$cmd.findOne({drop:	
  "foo"});

                 =
db.$cmd.find({drop:	
  "foo"}).limit(-­‐1);
Capped Collections
            preallocated
      auto	
  LRI	
  age-­‐out
     no	
  default	
  _id	
  index
   always	
  in	
  insertion	
  order




  http://www.mongodb.org/display/DOCS/Capped+Collections
Replication Oplog
                                            >	
  use	
  local
                                            switched	
  to	
  db	
  local
>	
  use	
  foo                             >	
  db.oplog.$main.find()
switched	
  to	
  db	
  foo                 {ts:	
  ...,	
  op:	
  "n",	
  ns:	
  "",	
  o:	
  {}}
                                            {ts:	
  ...,	
  op:	
  "n",	
  ns:	
  "",	
  o:	
  {}}
>	
  db.test.insert({x:	
  1,	
  url:	
     {ts:	
  ...,	
  op:	
  "i",	
  ns:	
  "foo.test",	
  
"http://dirolf.com"});                      	
  o:	
  {_id:	
  ObjectId("..."),
                                            	
  	
  	
  	
  	
  x:	
  1,
                                            	
  	
  	
  	
  	
  url:	
  "http://dirolf.com"}}
                                            {ts:	
  ...,	
  op:	
  "n",	
  ns:	
  "",	
  o:	
  {}}
>	
  db.test.update({url:	
  "http://       {ts:	
  ...,	
  op:	
  "u",	
  ns:	
  "foo.test",
dirolf.com"},	
  {$inc:	
  {x:	
  1}});     	
  o2:	
  {_id:	
  ObjectId("...")},
                                            	
  o:	
  {$set:	
  {x:	
  2}}}



                               http://www.mongodb.org/display/DOCS/Replication
Replication Topology
                                         master           slave

        master
                                         master           slave


slave       slave        slave           master          master

                                          slave          master



                    http://www.mongodb.org/display/DOCS/Replication
Auto-Sharding
                      Shards
          mongod      mongod       mongod
                                                   ...
Config     mongod     mongod        mongod
Servers

mongod

mongod

mongod
                      mongos      mongos     ...


                       client
            http://www.mongodb.org/display/DOCS/Sharding
Geohashing
                              (20,	
  10)
             (0001	
  0100,	
  0000	
  1010)
                0000	
  0010	
  0110	
  0100

maps	
  close	
  coordinates	
  (21,	
  9)	
  to	
  close	
  hashes:
             0000	
  0010	
  0110	
  0011

   tricky	
  part	
  happens	
  at	
  bit-­‐flips	
  (127	
  vs	
  128)

          http://www.mongodb.org/display/DOCS/Geospatial+Indexing
Download MongoDB
            http://www.mongodb.org




these	
  slides	
  are	
  available	
  at	
  http://dirolf.com
Ad

Recommended

MongodB Internals
MongodB Internals
Norberto Leite
 
An Introduction to MongoDB Ops Manager
An Introduction to MongoDB Ops Manager
MongoDB
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Kenny Gryp
 
MongoDB WiredTiger Internals
MongoDB WiredTiger Internals
Norberto Leite
 
PMM database open source monitoring solution
PMM database open source monitoring solution
Lior Altarescu
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
Morgan Tocker
 
ProxySQL for MySQL
ProxySQL for MySQL
Mydbops
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
MongoDB: How it Works
MongoDB: How it Works
Mike Dirolf
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
Mydbops
 
Introduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Introduction to MongoDB
Introduction to MongoDB
MongoDB
 
Indexing
Indexing
Mike Dirolf
 
Parquet Hadoop Summit 2013
Parquet Hadoop Summit 2013
Julien Le Dem
 
MyRocks Deep Dive
MyRocks Deep Dive
Yoshinori Matsunobu
 
Storing 16 Bytes at Scale
Storing 16 Bytes at Scale
Fabian Reinartz
 
Elastic Stack Introduction
Elastic Stack Introduction
Vikram Shinde
 
MongoDB Performance Tuning
MongoDB Performance Tuning
MongoDB
 
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB
 
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
Altinity Ltd
 
Indexing with MongoDB
Indexing with MongoDB
MongoDB
 
Apache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012
Jay Patel
 
The Right (and Wrong) Use Cases for MongoDB
The Right (and Wrong) Use Cases for MongoDB
MongoDB
 
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB
 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB
 
RocksDB detail
RocksDB detail
MIJIN AN
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
Deciphering Explain Output
Deciphering Explain Output
MongoDB
 

More Related Content

What's hot (20)

MongoDB: How it Works
MongoDB: How it Works
Mike Dirolf
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
Mydbops
 
Introduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Introduction to MongoDB
Introduction to MongoDB
MongoDB
 
Indexing
Indexing
Mike Dirolf
 
Parquet Hadoop Summit 2013
Parquet Hadoop Summit 2013
Julien Le Dem
 
MyRocks Deep Dive
MyRocks Deep Dive
Yoshinori Matsunobu
 
Storing 16 Bytes at Scale
Storing 16 Bytes at Scale
Fabian Reinartz
 
Elastic Stack Introduction
Elastic Stack Introduction
Vikram Shinde
 
MongoDB Performance Tuning
MongoDB Performance Tuning
MongoDB
 
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB
 
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
Altinity Ltd
 
Indexing with MongoDB
Indexing with MongoDB
MongoDB
 
Apache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012
Jay Patel
 
The Right (and Wrong) Use Cases for MongoDB
The Right (and Wrong) Use Cases for MongoDB
MongoDB
 
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB
 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB
 
RocksDB detail
RocksDB detail
MIJIN AN
 
MongoDB: How it Works
MongoDB: How it Works
Mike Dirolf
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
Mydbops
 
Introduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Introduction to MongoDB
Introduction to MongoDB
MongoDB
 
Parquet Hadoop Summit 2013
Parquet Hadoop Summit 2013
Julien Le Dem
 
Storing 16 Bytes at Scale
Storing 16 Bytes at Scale
Fabian Reinartz
 
Elastic Stack Introduction
Elastic Stack Introduction
Vikram Shinde
 
MongoDB Performance Tuning
MongoDB Performance Tuning
MongoDB
 
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB World 2019: The Sights (and Smells) of a Bad Query
MongoDB
 
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
Altinity Ltd
 
Indexing with MongoDB
Indexing with MongoDB
MongoDB
 
Apache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012
Jay Patel
 
The Right (and Wrong) Use Cases for MongoDB
The Right (and Wrong) Use Cases for MongoDB
MongoDB
 
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB World 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB
 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability Practices
Yoshinori Matsunobu
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB
 
RocksDB detail
RocksDB detail
MIJIN AN
 

Viewers also liked (10)

MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
Deciphering Explain Output
Deciphering Explain Output
MongoDB
 
MongoDB Performance Tuning
MongoDB Performance Tuning
Puneet Behl
 
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
MongoDB
 
MongoDB Basic Concepts
MongoDB Basic Concepts
MongoDB
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDB
MongoDB
 
Availability and scalability in mongo
Availability and scalability in mongo
Md. Khairul Anam
 
Performance Tuning and Optimization
Performance Tuning and Optimization
MongoDB
 
Scaling and Transaction Futures
Scaling and Transaction Futures
MongoDB
 
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
MongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
Deciphering Explain Output
Deciphering Explain Output
MongoDB
 
MongoDB Performance Tuning
MongoDB Performance Tuning
Puneet Behl
 
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
MongoDB
 
MongoDB Basic Concepts
MongoDB Basic Concepts
MongoDB
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDB
MongoDB
 
Availability and scalability in mongo
Availability and scalability in mongo
Md. Khairul Anam
 
Performance Tuning and Optimization
Performance Tuning and Optimization
MongoDB
 
Scaling and Transaction Futures
Scaling and Transaction Futures
MongoDB
 
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
MongoDB
 
Ad

Similar to Inside MongoDB: the Internals of an Open-Source Database (20)

FrozenRails Training
FrozenRails Training
Mike Dirolf
 
mongodb-introduction
mongodb-introduction
Tse-Ching Ho
 
MongoDB Live Hacking
MongoDB Live Hacking
Tobias Trelle
 
2012 phoenix mug
2012 phoenix mug
Paul Pedersen
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
WebGeek Philippines
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
Mongodb intro
Mongodb intro
christkv
 
MongoDB at FrozenRails
MongoDB at FrozenRails
Mike Dirolf
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
How MongoDB works
How MongoDB works
Vladimir Miguro
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS
Chris Harris
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
Night Sailer
 
Mongodb workshop
Mongodb workshop
Harun Yardımcı
 
MongoDB Command Line Tools
MongoDB Command Line Tools
Rainforest QA
 
MongoDB开发应用实践
MongoDB开发应用实践
iammutex
 
Scaling with MongoDB
Scaling with MongoDB
Rick Copeland
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and Queueing
Boxed Ice
 
Latinoware
Latinoware
kchodorow
 
FrozenRails Training
FrozenRails Training
Mike Dirolf
 
mongodb-introduction
mongodb-introduction
Tse-Ching Ho
 
MongoDB Live Hacking
MongoDB Live Hacking
Tobias Trelle
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
WebGeek Philippines
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
Mongodb intro
Mongodb intro
christkv
 
MongoDB at FrozenRails
MongoDB at FrozenRails
Mike Dirolf
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS
Chris Harris
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
Night Sailer
 
MongoDB Command Line Tools
MongoDB Command Line Tools
Rainforest QA
 
MongoDB开发应用实践
MongoDB开发应用实践
iammutex
 
Scaling with MongoDB
Scaling with MongoDB
Rick Copeland
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and Queueing
Boxed Ice
 
Ad

More from Mike Dirolf (15)

Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
 
Python Development (MongoSF)
Python Development (MongoSF)
Mike Dirolf
 
MongoDB at ZPUGDC
MongoDB at ZPUGDC
Mike Dirolf
 
MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)
Mike Dirolf
 
MongoDB at CodeMash 2.0.1.0
MongoDB at CodeMash 2.0.1.0
Mike Dirolf
 
MongoDB at RubyConf
MongoDB at RubyConf
Mike Dirolf
 
MongoDB at RuPy
MongoDB at RuPy
Mike Dirolf
 
MongoDB at RubyEnRails 2009
MongoDB at RubyEnRails 2009
Mike Dirolf
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
Mike Dirolf
 
MongoDB Hadoop DC
MongoDB Hadoop DC
Mike Dirolf
 
MongoDB London PHP
MongoDB London PHP
Mike Dirolf
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009
Mike Dirolf
 
MongoDB NYC Python
MongoDB NYC Python
Mike Dirolf
 
MongoDB SF Python
MongoDB SF Python
Mike Dirolf
 
MongoDB SF Ruby
MongoDB SF Ruby
Mike Dirolf
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
 
Python Development (MongoSF)
Python Development (MongoSF)
Mike Dirolf
 
MongoDB at ZPUGDC
MongoDB at ZPUGDC
Mike Dirolf
 
MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)
Mike Dirolf
 
MongoDB at CodeMash 2.0.1.0
MongoDB at CodeMash 2.0.1.0
Mike Dirolf
 
MongoDB at RubyConf
MongoDB at RubyConf
Mike Dirolf
 
MongoDB at RubyEnRails 2009
MongoDB at RubyEnRails 2009
Mike Dirolf
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
Mike Dirolf
 
MongoDB Hadoop DC
MongoDB Hadoop DC
Mike Dirolf
 
MongoDB London PHP
MongoDB London PHP
Mike Dirolf
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009
Mike Dirolf
 
MongoDB NYC Python
MongoDB NYC Python
Mike Dirolf
 
MongoDB SF Python
MongoDB SF Python
Mike Dirolf
 

Recently uploaded (20)

FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Data Validation and System Interoperability
Data Validation and System Interoperability
Safe Software
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
“Addressing Evolving AI Model Challenges Through Memory and Storage,” a Prese...
Edge AI and Vision Alliance
 

Inside MongoDB: the Internals of an Open-Source Database

  • 1. Mike  Dirolf  -­‐  @mdirolf  -­‐  10gen,  Inc. http://www.mongodb.org
  • 3. a word of warning this  talk  might  be  a  bit  “hard”, but  MongoDB  is  really  easy: http://try.mongodb.org
  • 5. _id if  not  specified  drivers  will  add  default: ObjectId("4bface1a2231316e04f3c434") timestamp machine  id process  id counter http://www.mongodb.org/display/DOCS/Object+IDs
  • 6. BSON Encoding {_id:  ObjectId(XXXXXXXXXXXX),  hello:  “world”} x27x00x00x00x07      _      i      dx00      X          X      X      X      X      X      X      X      X      X      X      Xx02      h      e      l      l      ox00x06x00 x00x00      w      o      r      l      dx00x00 http://bsonspec.org
  • 7. Insert Message (TCP/IP) message  length request  id response  id op  code  (insert) x68x00x00x00 xXXxXXxXXxXX x00x00x00x00 xd2x07x00x00 reserved collection  name document(s) x00x00x00x00 f  o  o  .  t  e  s  t  x00 BSON  Data http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
  • 8. Data File Allocation $  ls  -­‐sk  /data/db/ }  16384  foo.ns allocated  per   (up  to  2  gigs){ double  in  size    65536  foo.0 131072  foo.1 database  16384  bar.ns              ...
  • 10. Extent Allocation foo.0 allocated  per  namespace: foo.1 foo.test 00000000000 foo.bar foo.baz 00000000000 00000000000 foo.$freelist 00000000000 0000 preallocated  space foo.2 00000000000 00000000000 ns  details  stored  in  foo.ns 00000000000 00000000000
  • 11. Record Allocation ... Header  (Size,  Offset,  Next,  Prev) BSON  Data Padding Deleted  Record  (Size,  Offset,  Next) ...
  • 12. Indexing B-­‐Tree  indexes,  stored  in  own  namespaces >  db.system.namespaces.find() {  "name"  :  "foo.system.indexes"  } {  "name"  :  "foo.test"  } {  "name"  :  "foo.test.$_id_"  } http://www.mongodb.org/display/DOCS/Indexes
  • 14. Query Language “query  by  example”  plus  $  modifiers: {first_name:  “Mike”,  age:  {$gte:  20,  $lt:  40}} http://www.mongodb.org/display/DOCS/Advanced+Queries
  • 15. Cursors >  var  c  =  db.test.find({x:  20}).skip(20).limit(10) >  c.next() >  c.next()      ... query first  N  results  +  cursor  id getMore  w/  cursor  id next  N  results  +  cursor  id  or  0 ...
  • 16. Query Optimizer find({x:  10,  y:  “foo”})    scan terminate    index  on  x    index  on  y remember
  • 18. Commands drop,  count,  copydb,   findAndModify,  serverStatus,  ... http://www.mongodb.org/display/DOCS/Commands
  • 19. db.foo.drop(); = db.foo.runCommand({drop:  "foo"}); = db.$cmd.findOne({drop:  "foo"}); = db.$cmd.find({drop:  "foo"}).limit(-­‐1);
  • 20. Capped Collections preallocated auto  LRI  age-­‐out no  default  _id  index always  in  insertion  order http://www.mongodb.org/display/DOCS/Capped+Collections
  • 21. Replication Oplog >  use  local switched  to  db  local >  use  foo >  db.oplog.$main.find() switched  to  db  foo {ts:  ...,  op:  "n",  ns:  "",  o:  {}} {ts:  ...,  op:  "n",  ns:  "",  o:  {}} >  db.test.insert({x:  1,  url:   {ts:  ...,  op:  "i",  ns:  "foo.test",   "http://dirolf.com"});  o:  {_id:  ObjectId("..."),          x:  1,          url:  "http://dirolf.com"}} {ts:  ...,  op:  "n",  ns:  "",  o:  {}} >  db.test.update({url:  "http:// {ts:  ...,  op:  "u",  ns:  "foo.test", dirolf.com"},  {$inc:  {x:  1}});  o2:  {_id:  ObjectId("...")},  o:  {$set:  {x:  2}}} http://www.mongodb.org/display/DOCS/Replication
  • 22. Replication Topology master slave master master slave slave slave slave master master slave master http://www.mongodb.org/display/DOCS/Replication
  • 23. Auto-Sharding Shards mongod mongod mongod ... Config mongod mongod mongod Servers mongod mongod mongod mongos mongos ... client http://www.mongodb.org/display/DOCS/Sharding
  • 24. Geohashing (20,  10) (0001  0100,  0000  1010) 0000  0010  0110  0100 maps  close  coordinates  (21,  9)  to  close  hashes: 0000  0010  0110  0011 tricky  part  happens  at  bit-­‐flips  (127  vs  128) http://www.mongodb.org/display/DOCS/Geospatial+Indexing
  • 25. Download MongoDB http://www.mongodb.org these  slides  are  available  at  http://dirolf.com