Breaking performance barriers with MongoDB

A.K.A How to convince Drupal to love MongoDB

Janez Urevc / @slashrsm

Photo by Dan McCreary - http://www.flickr.com/photos/25086260

MongoDB?

  • document-oriented storage
  • free software - GNU AGPL v3.0 (DBMS), Apache (drivers)
  • can store complex data structures
  • stores data as JSON documents
  • schemaless
  • MongoDB company (professional support, training, ...)

> show dbs;
local	0.078125GB
> use drupal;
> show collections;
> db.awesomestuff.insert({"a":1, "b":2});
> db.awesomestuff.find();
{"_id":ObjectId("526965cd93259605e9afbc41"), "a":1, "b":2}
> show collections;
system.indexes
awesomestuff
            

> db.awesomestuff.insert({"a": [1, 2, 3], "b":"some string"});
> db.awesomestuff.insert({"a": [[1,2,4], [4,5,6], [7,8,9]]});
> db.awesomestuff.insert({
  "a": {
    "name" : "foo",
    "interests" : ["Drupal", "MongoDB"]
  }
);
            

What else?

  • no joins
  • no transactions
  • allows you to index on anything
  • seamless replication and scaling (sharding)
  • capped collections
  • geospatial indexes
  • aggregation framework
MySQL MongoDB
database database
table collection
row document
column field
index index
joins embedded documents and linking

persistent, easy to set-up, fast ("fire and forget"), automatic garbage collection

Photo by http://www.webdesignerdepot.com/2009/03/40-comics-strips-for-web-designers/

easy to set-up, fast ("fire and forget"), very good for multi-server envs, uses capped collections

Photo by Which? Campaigns - http://www.flickr.com/photos/71528417

easy to set-up, per-queue-colection

Photo by Darren Tunnicliff - http://www.flickr.com/photos/25572591

a bit funky :), stores blocks configuration, exposes UI

Photo by capitaine_commerce - http://www.flickr.com/photos/8488292

Field storage

stores entites /w fields as Mongo docs, still needs base entity table, lazy destruction of stale data, new fields added very easily

Photo by capitaine_commerce - http://www.flickr.com/photos/8488292

{
  "_id" : 60549286,
  "_type" : "node",
  "_bundle" : "story",
  "_revision_id" : 150412786,
  "nid" : 60549286,
  "vid" : 150412786,
  "type" : "story",
  "language" : "und",
  "title" : "Hello world!",
  "uid" : 2044271,
  "status" : 1,
  "created" : 1364855903,
  "changed" : 1364855940,
  "comment" : 2,
  "promote" : 1,
  "sticky" : 0,
  "field_image" : {
    "fid" : 47928616,
    "width" : 594,
    "height" : 396,
    "alt" : "",
    "title" : ""
  },
  "body" : {
    "value" : "

MongoDB is great!

" }, "field_tags" : [ { "tid" : 14244596 }, { "tid" : 14244596 } ] }

Other stuff

  • locking backend
  • sessions storage
  • Entity (field) query

Conclusion

  • you cannot run away from MySQL (yet)
  • you can use mongo to achieve performance improvements
  • cannot be used with Views (yet)
  • you need to know why you're going to use MongoDB

Want more?

Thank you!

Questions?

Janez Urevc / @slashrsm