SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDBMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMongoDB
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack PresentationAmr Alaa Yassen
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationEDB
 
MongoDB at Baidu
MongoDB at BaiduMongoDB at Baidu
MongoDB at BaiduMat Keep
 
Apache Spark overview
Apache Spark overviewApache Spark overview
Apache Spark overviewDataArt
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]MongoDB
 
Building a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLBuilding a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLDatabricks
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Apache Sqoop: A Data Transfer Tool for Hadoop
Apache Sqoop: A Data Transfer Tool for HadoopApache Sqoop: A Data Transfer Tool for Hadoop
Apache Sqoop: A Data Transfer Tool for HadoopCloudera, Inc.
 
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performanceMariaDB plc
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용I Goo Lee
 

Tendances (20)

Sharding Methods for MongoDB
Sharding Methods for MongoDBSharding Methods for MongoDB
Sharding Methods for MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack Presentation
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
Dive into PySpark
Dive into PySparkDive into PySpark
Dive into PySpark
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
Apache Spark Architecture
Apache Spark ArchitectureApache Spark Architecture
Apache Spark Architecture
 
MongoDB at Baidu
MongoDB at BaiduMongoDB at Baidu
MongoDB at Baidu
 
Apache Spark overview
Apache Spark overviewApache Spark overview
Apache Spark overview
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Postgresql
PostgresqlPostgresql
Postgresql
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
 
Building a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLBuilding a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQL
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Apache Sqoop: A Data Transfer Tool for Hadoop
Apache Sqoop: A Data Transfer Tool for HadoopApache Sqoop: A Data Transfer Tool for Hadoop
Apache Sqoop: A Data Transfer Tool for Hadoop
 
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performance
 
MongoDB
MongoDBMongoDB
MongoDB
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용
 

En vedette

MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
Deciphering Explain Output
Deciphering Explain Output Deciphering Explain Output
Deciphering Explain Output MongoDB
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger InternalsNorberto Leite
 
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDBTrading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDBMongoDB
 
MongoDB Basic Concepts
MongoDB Basic ConceptsMongoDB Basic Concepts
MongoDB Basic ConceptsMongoDB
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDBMongoDB
 
Availability and scalability in mongo
Availability and scalability in mongoAvailability and scalability in mongo
Availability and scalability in mongoMd. Khairul Anam
 
Performance Tuning and Optimization
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and OptimizationMongoDB
 
Scaling and Transaction Futures
Scaling and Transaction FuturesScaling and Transaction Futures
Scaling and Transaction FuturesMongoDB
 
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)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
 

En vedette (11)

MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
Deciphering Explain Output
Deciphering Explain Output Deciphering Explain Output
Deciphering Explain Output
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDBTrading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
Trading up: Adding Flexibility and Scalability to Bouygues Telecom with MongoDB
 
MongoDB Basic Concepts
MongoDB Basic ConceptsMongoDB Basic Concepts
MongoDB Basic Concepts
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDB
 
Indexing
IndexingIndexing
Indexing
 
Availability and scalability in mongo
Availability and scalability in mongoAvailability and scalability in mongo
Availability and scalability in mongo
 
Performance Tuning and Optimization
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and Optimization
 
Scaling and Transaction Futures
Scaling and Transaction FuturesScaling and Transaction Futures
Scaling and Transaction Futures
 
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)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)
 

Similaire à Inside MongoDB: the Internals of an Open-Source Database

FrozenRails Training
FrozenRails TrainingFrozenRails Training
FrozenRails TrainingMike Dirolf
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDBTakahiro Inoue
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBAlex Bilbie
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...MongoDB
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Andrii Lashchenko
 
An introduction to CouchDB
An introduction to CouchDBAn introduction to CouchDB
An introduction to CouchDBDavid Coallier
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsIvan Shcheklein
 
Mongophilly shell-2011-04-26
Mongophilly shell-2011-04-26Mongophilly shell-2011-04-26
Mongophilly shell-2011-04-26kreuter
 

Similaire à Inside MongoDB: the Internals of an Open-Source Database (20)

FrozenRails Training
FrozenRails TrainingFrozenRails Training
FrozenRails Training
 
Latinoware
LatinowareLatinoware
Latinoware
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
 
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp KrennJavantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Trimming The Cruft
Trimming The CruftTrimming The Cruft
Trimming The Cruft
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
An introduction to CouchDB
An introduction to CouchDBAn introduction to CouchDB
An introduction to CouchDB
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor Internals
 
Mongophilly shell-2011-04-26
Mongophilly shell-2011-04-26Mongophilly shell-2011-04-26
Mongophilly shell-2011-04-26
 

Plus de Mike Dirolf

Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYCMike Dirolf
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRailsMike Dirolf
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDCMike Dirolf
 
MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)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.0MongoDB at CodeMash 2.0.1.0
MongoDB at CodeMash 2.0.1.0Mike Dirolf
 
MongoDB at RubyConf
MongoDB at RubyConfMongoDB at RubyConf
MongoDB at RubyConfMike Dirolf
 
MongoDB at RubyEnRails 2009
MongoDB at RubyEnRails 2009MongoDB at RubyEnRails 2009
MongoDB at RubyEnRails 2009Mike Dirolf
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009Mike Dirolf
 
MongoDB Hadoop DC
MongoDB Hadoop DCMongoDB Hadoop DC
MongoDB Hadoop DCMike Dirolf
 
MongoDB London PHP
MongoDB London PHPMongoDB London PHP
MongoDB London PHPMike Dirolf
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009MongoDB EuroPython 2009
MongoDB EuroPython 2009Mike Dirolf
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC PythonMike Dirolf
 
MongoDB SF Python
MongoDB SF PythonMongoDB SF Python
MongoDB SF PythonMike Dirolf
 

Plus de Mike Dirolf (16)

Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDC
 
MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)
 
MongoDB at CodeMash 2.0.1.0
MongoDB at CodeMash 2.0.1.0MongoDB at CodeMash 2.0.1.0
MongoDB at CodeMash 2.0.1.0
 
MongoDB at RubyConf
MongoDB at RubyConfMongoDB at RubyConf
MongoDB at RubyConf
 
MongoDB at RuPy
MongoDB at RuPyMongoDB at RuPy
MongoDB at RuPy
 
MongoDB at RubyEnRails 2009
MongoDB at RubyEnRails 2009MongoDB at RubyEnRails 2009
MongoDB at RubyEnRails 2009
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
 
MongoDB Hadoop DC
MongoDB Hadoop DCMongoDB Hadoop DC
MongoDB Hadoop DC
 
MongoDB London PHP
MongoDB London PHPMongoDB London PHP
MongoDB London PHP
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009MongoDB EuroPython 2009
MongoDB EuroPython 2009
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC Python
 
MongoDB SF Python
MongoDB SF PythonMongoDB SF Python
MongoDB SF Python
 
MongoDB SF Ruby
MongoDB SF RubyMongoDB SF Ruby
MongoDB SF Ruby
 

Dernier

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Dernier (20)

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

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