SlideShare a Scribd company logo
1 of 40
Download to read offline
d60
developing smart software solutions
                                      So you want to liberate your data?
                                                                 April 2012
Mogens	
  Heller	
  Grabe	
  
            	
  
            	
  
             	
  
      mhg@d60.dk	
  
      @mookid8000	
  
 h8p://mookid.dk/oncode	
  
Agenda	
  
•    Data,	
  queries,	
  etc.	
  
•    Concurrency	
  
•    AggregaEon	
  
•    Deployment	
  
•    Durability	
  
•    Things	
  to	
  be	
  aware	
  of	
  
MongoDB	
  
•    Document	
  database	
  
•    Currently	
  in	
  v.	
  2.0.4	
  
•    Developed	
  by	
  10gen	
  
•    Open	
  source	
  
      –  server	
  is	
  GNU	
  AGPL	
  v3	
  
      –  clients	
  (the	
  official)	
  are	
  Apache	
  V2	
  
•  Absolutely	
  free	
  to	
  use	
  
      –  you	
  can	
  get	
  a	
  commercial	
  version	
  of	
  the	
  db	
  though	
  –	
  has	
  
         support,	
  SSL,	
  and	
  more	
  security	
  features	
  
Conceptual	
  data	
  organizaEon	
  




       process
                 database
                         collection
                                   document

       process
                 database
                         table
                                 row
Data	
  
Example	
  1	
  
•    Install	
  
•    Mongo	
  Shell	
  
•    Show	
  database	
  contents	
  
•    Add	
  and	
  show	
  a	
  document	
  
Queries	
  




including	
  several	
  other	
  query	
  operators:	
  
$gt,	
  $gte,	
  $lt,	
  $lte,	
  $exists,	
  $all,	
  etc...	
  
Indexes	
  
Updates	
  




including	
  several	
  other	
  update	
  modifiers:	
  
$inc,	
  $set,	
  $addToSet,	
  $rename,	
  etc...	
  
Example	
  2	
  
•    Import	
  some	
  data	
  
•    Query	
  
•    Update	
  
•    Index	
  
•    Query	
  
ACID?	
  
•    Atomic:	
  Yeah	
  well,	
  per	
  document.	
  
•    Consistent:	
  Yeah	
  well,	
  can	
  be.	
  
•    Isolated:	
  Yeah	
  well,	
  per	
  document.	
  
•    Durable:	
  Yeah	
  well,	
  can	
  be	
  –	
  not	
  default	
  
     though....	
  
Concurrency	
  
•  Pushing	
  it	
  down	
  the	
  stack	
  
Concurrency	
  
•  Preserve	
  invariants	
  with	
  update	
  precondiEons	
  
Concurrency	
  
•  Use	
  opEmisEc	
  
   locking	
  when	
  
   replacing	
  
   document	
  

	
  (and	
  then	
  check	
  whether	
  n	
  
is	
  0	
  or	
  1...)	
  
Concurrency	
  
•  Use	
  FindAndModify	
  to	
  “check	
  out”	
  documents	
  
AggregaEon	
  
•  Map/reduce	
  
AggregaEon	
  
•  Map/reduce	
  
   –  Map:	
  
      for	
  each	
  document:	
  
     	
  emit	
  0	
  or	
  more	
  (key,	
  value)	
  tuples	
  
   –  Reduce:	
  
      given	
  a	
  (key,	
  value[]),	
  
     	
  return	
  1	
  value	
  
AggregaEon	
  
m	
  =	
  function()	
  {	
  
	
  	
  	
  	
  var	
  doc	
  =	
  this;	
  
	
  	
  	
  	
  doc.appearances.forEach(function(a)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  emit(a,	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  count:	
  1,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  names:	
  [doc.firstName	
  +	
  “	
  “	
  +	
  doc.lastName]	
  
	
  	
  	
  	
  	
  	
  	
  	
  });	
  
	
  	
  	
  	
  });	
  
}	
  
	
  
r	
  =	
  function(key,	
  values)	
  {	
  
	
  	
  	
  	
  var	
  count	
  =	
  0;	
  
	
  	
  	
  	
  var	
  names	
  =	
  [];	
  
	
  	
  	
  	
  values.forEach(function(v)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  count	
  +=	
  v.count;	
  
	
  	
  	
  	
  	
  	
  	
  	
  names	
  =	
  names.concat(v.names);	
  
	
  	
  	
  	
  });	
  
	
  	
  	
  	
  return	
  {count:	
  count,	
  names:	
  names};	
  
}	
  
Example	
  3	
  
•  Use	
  map/reduce	
  to	
  collect	
  informaEon	
  on	
  
   who	
  appeared	
  in	
  each	
  episode	
  
AggregaEon	
  
•  AggregaEon	
  framework	
  (not	
  available	
  unEl	
  
   2.2)	
  
   –  declaraEve	
  syntax	
  for	
  construcEon	
  of	
  an	
  
      aggregaEon	
  pipeline	
  
AggregaEon	
  
•  AggregaEon	
  framework	
  (not	
  available	
  unEl	
  
   2.2)	
  
Deployment	
  
•  Several	
  configuraEons	
  
   –  we’ll	
  check	
  out	
  replica	
  sets	
  and	
  sharding	
  
Replica	
  sets	
  
•  Master-­‐slave	
  with	
  automaEc	
  failover	
  
   –  Each	
  mongod	
  should	
  be	
  started	
  with	
  the	
  -­‐-­‐replset	
  
      argument	
  
   –  AddiEonal	
  nodes	
  added	
  from	
  the	
  shell	
  
   –  Make	
  sure	
  the	
  number	
  of	
  nodes	
  is	
  odd,	
  possibly	
  
      by	
  adding	
  an	
  arbiter	
  
Replica	
  sets	
  
•  Higher	
  availability	
  
•  Scale	
  out	
  reads	
  
•  Backup	
  without	
  interfering	
  with	
  the	
  primary	
  
Sharding	
  
•  Auto-­‐sharding	
  
   –  happens	
  by	
  user-­‐defined	
  
      shard	
  key	
  
   –  can	
  be	
  defined	
  per	
  
      collecEon	
  
   –  requires	
  special	
  nodes:	
  
      mongos	
  (the	
  load	
  
      balancer)	
  and	
  a	
  mongod	
  
      that	
  is	
  configured	
  to	
  be	
  a	
  
      configuraEon	
  server	
  
Sharding	
  
•  Scale	
  out	
  writes	
  

•  LimitaEons:	
  
    –  Shard	
  key	
  is	
  immutable	
  
    –  All	
  inserts/updates	
  must	
  include	
  the	
  shard	
  key	
  
    –  Cannot	
  enforce	
  (arbitrary)	
  uniqueness	
  across	
  
       shards,	
  only	
  for	
  shard	
  key	
  
Sharding	
  +	
  replica	
  sets	
  
MongoDB’s	
  durability	
  story	
  
•  Memory-­‐mapped	
  files.	
  
•  fsync.	
  

•  Durability	
  through	
  replicaEon	
  
   –  pre	
  1.8	
  
•  Durability	
  through	
  journaling	
  
   –  an	
  opEon	
  since	
  1.8	
  –	
  replica	
  sets	
  sEll	
  cool	
  though	
  
   –  default	
  since	
  2.0	
  
MongoDB’s	
  durability	
  story	
  
•  Inserts	
  and	
  updates	
  are	
  unsafe	
  by	
  default!!	
  
    –  only	
  purpose:	
  get	
  awesome	
  benchmarks	
  
    –  bad:	
  bites	
  you	
  in	
  the	
  a**	
  


•  Exposed	
  differently	
  on	
  drivers,	
  but	
  always	
  
   maps	
  to	
  db.getLastError()	
  
MongoDB’s	
  durability	
  story	
  
•  Conclusion:	
  It’s	
  cool	
  that	
  you	
  can	
  
   tweak	
  it	
  per	
  operation,	
  but	
  it’s	
  
   uncool	
  that	
  it’s	
  unsafe.	
  
Things	
  to	
  be	
  aware	
  of	
  
•    Safe	
  mode	
  off	
  
•    32/64	
  bit	
  
•    Memory-­‐mapped	
  file	
  
•    Global	
  write	
  lock	
  
•    Indexes	
  should	
  always	
  fit	
  in	
  RAM	
  
Thanks	
  for	
  listening!	
  
        mhg@d60.dk	
  
        @mookid8000	
  
   h8p://mookid.dk/oncode	
  
Image	
  credits	
  
The	
  world’s	
  most	
  interesEng	
  man:	
  h8p://i.qkme.me/3mwy.jpg	
  
Bison:	
  h8p://www.flickr.com/photos/johan-­‐gril/5632513228/	
  
Tired	
  Fry:	
  h8p://cdn.memegenerator.net/instances/400x/18731987.jpg	
  	
  	
  
	
  	
  
	
  
	
  
Thanks	
  for	
  lerng	
  me	
  borrow	
  your	
  awesome	
  images	
  –	
  if	
  you	
  ever	
  meet	
  me,	
  I’ll	
  buy	
  you	
  a	
  beer.	
  Seriously,	
  I	
  will.	
  

More Related Content

What's hot

Redis overview for Software Architecture Forum
Redis overview for Software Architecture ForumRedis overview for Software Architecture Forum
Redis overview for Software Architecture ForumChristopher Spring
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)Felix Geisendörfer
 
Intro to GemStone/S
Intro to GemStone/SIntro to GemStone/S
Intro to GemStone/SESUG
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Andreas Jung
 
Bulk Loading Data into Cassandra
Bulk Loading Data into CassandraBulk Loading Data into Cassandra
Bulk Loading Data into CassandraDataStax
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2Dvir Volk
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Felix Geisendörfer
 
Dirty - How simple is your database?
Dirty - How simple is your database?Dirty - How simple is your database?
Dirty - How simple is your database?Felix Geisendörfer
 
Boosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkBoosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkDvir Volk
 
PhpTour Lyon 2014 - Transparent caching & context aware http cache
PhpTour Lyon 2014 - Transparent caching & context aware http cachePhpTour Lyon 2014 - Transparent caching & context aware http cache
PhpTour Lyon 2014 - Transparent caching & context aware http cacheAndré Rømcke
 
Introduction of mesos persistent storage
Introduction of mesos persistent storageIntroduction of mesos persistent storage
Introduction of mesos persistent storageZhou Weitao
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScriptQiangning Hong
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deploymentzeeg
 
CMUデータベース輪読会第8回
CMUデータベース輪読会第8回CMUデータベース輪読会第8回
CMUデータベース輪読会第8回Keisuke Suzuki
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structuresamix3k
 
Building and Deploying Application to Apache Mesos
Building and Deploying Application to Apache MesosBuilding and Deploying Application to Apache Mesos
Building and Deploying Application to Apache MesosJoe Stein
 

What's hot (20)

Redis overview for Software Architecture Forum
Redis overview for Software Architecture ForumRedis overview for Software Architecture Forum
Redis overview for Software Architecture Forum
 
How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)
 
Intro to GemStone/S
Intro to GemStone/SIntro to GemStone/S
Intro to GemStone/S
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
 
Bulk Loading Data into Cassandra
Bulk Loading Data into CassandraBulk Loading Data into Cassandra
Bulk Loading Data into Cassandra
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
 
Dirty - How simple is your database?
Dirty - How simple is your database?Dirty - How simple is your database?
Dirty - How simple is your database?
 
memcached Distributed Cache
memcached Distributed Cachememcached Distributed Cache
memcached Distributed Cache
 
Node.js in production
Node.js in productionNode.js in production
Node.js in production
 
Boosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkBoosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and Spark
 
PhpTour Lyon 2014 - Transparent caching & context aware http cache
PhpTour Lyon 2014 - Transparent caching & context aware http cachePhpTour Lyon 2014 - Transparent caching & context aware http cache
PhpTour Lyon 2014 - Transparent caching & context aware http cache
 
Introduction of mesos persistent storage
Introduction of mesos persistent storageIntroduction of mesos persistent storage
Introduction of mesos persistent storage
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deployment
 
CMUデータベース輪読会第8回
CMUデータベース輪読会第8回CMUデータベース輪読会第8回
CMUデータベース輪読会第8回
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structures
 
Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Building and Deploying Application to Apache Mesos
Building and Deploying Application to Apache MesosBuilding and Deploying Application to Apache Mesos
Building and Deploying Application to Apache Mesos
 

Viewers also liked

Taking the hippie bus to the enterprise
Taking the hippie bus to the enterpriseTaking the hippie bus to the enterprise
Taking the hippie bus to the enterpriseMogens Heller Grabe
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Viewers also liked (7)

Rebus er ingen gåde
Rebus er ingen gådeRebus er ingen gåde
Rebus er ingen gåde
 
Rebus er ingen gåde
Rebus er ingen gådeRebus er ingen gåde
Rebus er ingen gåde
 
Anexa 1 rebus
Anexa 1 rebusAnexa 1 rebus
Anexa 1 rebus
 
Taking the hippie bus to the enterprise
Taking the hippie bus to the enterpriseTaking the hippie bus to the enterprise
Taking the hippie bus to the enterprise
 
Ride The Bus!
Ride The Bus!Ride The Bus!
Ride The Bus!
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to So you want to liberate your data?

Scaling with mongo db (with notes)
Scaling with mongo db (with notes)Scaling with mongo db (with notes)
Scaling with mongo db (with notes)emiltamas
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsConcentric Sky
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
Data Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture PatternsData Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture PatternsHuahai Yang
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewAntonio Pintus
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPrashant Rane
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?DATAVERSITY
 
Mongo DB at Community Engine
Mongo DB at Community EngineMongo DB at Community Engine
Mongo DB at Community EngineCommunity Engine
 
MongoDB at community engine
MongoDB at community engineMongoDB at community engine
MongoDB at community enginemathraq
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment StrategiesMongoDB
 
Lessons Learned Running Hadoop and Spark in Docker Containers
Lessons Learned Running Hadoop and Spark in Docker ContainersLessons Learned Running Hadoop and Spark in Docker Containers
Lessons Learned Running Hadoop and Spark in Docker ContainersBlueData, Inc.
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbMongoDB APAC
 
Apache Spark Tutorial
Apache Spark TutorialApache Spark Tutorial
Apache Spark TutorialAhmet Bulut
 
MongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB
 
Ippevent : openshift Introduction
Ippevent : openshift IntroductionIppevent : openshift Introduction
Ippevent : openshift Introductionkanedafromparis
 
Kubernetes Internals
Kubernetes InternalsKubernetes Internals
Kubernetes InternalsShimi Bandiel
 
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps ItaliaWhen Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps ItaliaGiovanni Toraldo
 
Scality S3 Server: Node js Meetup Presentation
Scality S3 Server: Node js Meetup PresentationScality S3 Server: Node js Meetup Presentation
Scality S3 Server: Node js Meetup PresentationScality
 
Puppet Camp Dublin - 06/2012
Puppet Camp Dublin - 06/2012Puppet Camp Dublin - 06/2012
Puppet Camp Dublin - 06/2012Roland Tritsch
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 

Similar to So you want to liberate your data? (20)

Scaling with mongo db (with notes)
Scaling with mongo db (with notes)Scaling with mongo db (with notes)
Scaling with mongo db (with notes)
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Data Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture PatternsData Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture Patterns
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
 
Mongo DB at Community Engine
Mongo DB at Community EngineMongo DB at Community Engine
Mongo DB at Community Engine
 
MongoDB at community engine
MongoDB at community engineMongoDB at community engine
MongoDB at community engine
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 
Lessons Learned Running Hadoop and Spark in Docker Containers
Lessons Learned Running Hadoop and Spark in Docker ContainersLessons Learned Running Hadoop and Spark in Docker Containers
Lessons Learned Running Hadoop and Spark in Docker Containers
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
 
Apache Spark Tutorial
Apache Spark TutorialApache Spark Tutorial
Apache Spark Tutorial
 
MongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOLMongoDB: How We Did It – Reanimating Identity at AOL
MongoDB: How We Did It – Reanimating Identity at AOL
 
Ippevent : openshift Introduction
Ippevent : openshift IntroductionIppevent : openshift Introduction
Ippevent : openshift Introduction
 
Kubernetes Internals
Kubernetes InternalsKubernetes Internals
Kubernetes Internals
 
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps ItaliaWhen Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
 
Scality S3 Server: Node js Meetup Presentation
Scality S3 Server: Node js Meetup PresentationScality S3 Server: Node js Meetup Presentation
Scality S3 Server: Node js Meetup Presentation
 
Puppet Camp Dublin - 06/2012
Puppet Camp Dublin - 06/2012Puppet Camp Dublin - 06/2012
Puppet Camp Dublin - 06/2012
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

So you want to liberate your data?

  • 1. d60 developing smart software solutions So you want to liberate your data? April 2012
  • 2. Mogens  Heller  Grabe         mhg@d60.dk   @mookid8000   h8p://mookid.dk/oncode  
  • 3.
  • 4. Agenda   •  Data,  queries,  etc.   •  Concurrency   •  AggregaEon   •  Deployment   •  Durability   •  Things  to  be  aware  of  
  • 5. MongoDB   •  Document  database   •  Currently  in  v.  2.0.4   •  Developed  by  10gen   •  Open  source   –  server  is  GNU  AGPL  v3   –  clients  (the  official)  are  Apache  V2   •  Absolutely  free  to  use   –  you  can  get  a  commercial  version  of  the  db  though  –  has   support,  SSL,  and  more  security  features  
  • 6. Conceptual  data  organizaEon   process database collection document process database table row
  • 8. Example  1   •  Install   •  Mongo  Shell   •  Show  database  contents   •  Add  and  show  a  document  
  • 9. Queries   including  several  other  query  operators:   $gt,  $gte,  $lt,  $lte,  $exists,  $all,  etc...  
  • 11. Updates   including  several  other  update  modifiers:   $inc,  $set,  $addToSet,  $rename,  etc...  
  • 12. Example  2   •  Import  some  data   •  Query   •  Update   •  Index   •  Query  
  • 13. ACID?   •  Atomic:  Yeah  well,  per  document.   •  Consistent:  Yeah  well,  can  be.   •  Isolated:  Yeah  well,  per  document.   •  Durable:  Yeah  well,  can  be  –  not  default   though....  
  • 14. Concurrency   •  Pushing  it  down  the  stack  
  • 15. Concurrency   •  Preserve  invariants  with  update  precondiEons  
  • 16. Concurrency   •  Use  opEmisEc   locking  when   replacing   document    (and  then  check  whether  n   is  0  or  1...)  
  • 17. Concurrency   •  Use  FindAndModify  to  “check  out”  documents  
  • 19. AggregaEon   •  Map/reduce   –  Map:   for  each  document:    emit  0  or  more  (key,  value)  tuples   –  Reduce:   given  a  (key,  value[]),    return  1  value  
  • 20. AggregaEon   m  =  function()  {          var  doc  =  this;          doc.appearances.forEach(function(a)  {                  emit(a,  {                          count:  1,                            names:  [doc.firstName  +  “  “  +  doc.lastName]                  });          });   }     r  =  function(key,  values)  {          var  count  =  0;          var  names  =  [];          values.forEach(function(v)  {                  count  +=  v.count;                  names  =  names.concat(v.names);          });          return  {count:  count,  names:  names};   }  
  • 21. Example  3   •  Use  map/reduce  to  collect  informaEon  on   who  appeared  in  each  episode  
  • 22. AggregaEon   •  AggregaEon  framework  (not  available  unEl   2.2)   –  declaraEve  syntax  for  construcEon  of  an   aggregaEon  pipeline  
  • 23. AggregaEon   •  AggregaEon  framework  (not  available  unEl   2.2)  
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Deployment   •  Several  configuraEons   –  we’ll  check  out  replica  sets  and  sharding  
  • 29. Replica  sets   •  Master-­‐slave  with  automaEc  failover   –  Each  mongod  should  be  started  with  the  -­‐-­‐replset   argument   –  AddiEonal  nodes  added  from  the  shell   –  Make  sure  the  number  of  nodes  is  odd,  possibly   by  adding  an  arbiter  
  • 30. Replica  sets   •  Higher  availability   •  Scale  out  reads   •  Backup  without  interfering  with  the  primary  
  • 31. Sharding   •  Auto-­‐sharding   –  happens  by  user-­‐defined   shard  key   –  can  be  defined  per   collecEon   –  requires  special  nodes:   mongos  (the  load   balancer)  and  a  mongod   that  is  configured  to  be  a   configuraEon  server  
  • 32. Sharding   •  Scale  out  writes   •  LimitaEons:   –  Shard  key  is  immutable   –  All  inserts/updates  must  include  the  shard  key   –  Cannot  enforce  (arbitrary)  uniqueness  across   shards,  only  for  shard  key  
  • 34. MongoDB’s  durability  story   •  Memory-­‐mapped  files.   •  fsync.   •  Durability  through  replicaEon   –  pre  1.8   •  Durability  through  journaling   –  an  opEon  since  1.8  –  replica  sets  sEll  cool  though   –  default  since  2.0  
  • 35. MongoDB’s  durability  story   •  Inserts  and  updates  are  unsafe  by  default!!   –  only  purpose:  get  awesome  benchmarks   –  bad:  bites  you  in  the  a**   •  Exposed  differently  on  drivers,  but  always   maps  to  db.getLastError()  
  • 36.
  • 37. MongoDB’s  durability  story   •  Conclusion:  It’s  cool  that  you  can   tweak  it  per  operation,  but  it’s   uncool  that  it’s  unsafe.  
  • 38. Things  to  be  aware  of   •  Safe  mode  off   •  32/64  bit   •  Memory-­‐mapped  file   •  Global  write  lock   •  Indexes  should  always  fit  in  RAM  
  • 39. Thanks  for  listening!   mhg@d60.dk   @mookid8000   h8p://mookid.dk/oncode  
  • 40. Image  credits   The  world’s  most  interesEng  man:  h8p://i.qkme.me/3mwy.jpg   Bison:  h8p://www.flickr.com/photos/johan-­‐gril/5632513228/   Tired  Fry:  h8p://cdn.memegenerator.net/instances/400x/18731987.jpg               Thanks  for  lerng  me  borrow  your  awesome  images  –  if  you  ever  meet  me,  I’ll  buy  you  a  beer.  Seriously,  I  will.