You are on page 1of 14

Drupal and MongoDB

High Performance Meetup - LA February 2012 BTMash

Agenda
RDBMS: Issues What is MongoDB? About NoSQL / Document storage Queries Why MongoDB? Pros Cons What about Drupal? MongoDB module Field Queries Why Drupal + Mongo? Pros Setup + Demo Q&A

Relational DB Issues
Not all that much. HOWEVER: Once you have related data, you need to join them. Sometimes, indexing doesn't work very well. Introduce denormalization. Build extra tables. Changes can lock data. Downtime Load on system Code changes are not automatically coupled with schema changes. Coordination can be difficult.

What is MongoDB?
About MongoDB Document oriented NoSQL Database System Written in C++ Released in 2009 Query Results looks like JSON { "v" : 1, "key" : { "_id" : 1 }, "ns" : "db.fields_current.search_api_index", "name" : "_id_" } ...

What is MongoDB (cont'd)


Databases consist of collections Collections contains objects. CLI Queries are somewhat similar to sql (except not): db.fields_current.node.find({'uid': 0, 'field_field_name.value': 1}); db_fields_current.node.find({'_id': 100}); db.fields_current.node.find({'title': /about/i}, {title: true}).limit(4); db_fields_current.node.save(JSONified Node Object); Will update if the object id already exists. db_fields_current.node.remove({my_json_parameters});

Why MongoDB? Pros


Highly Available Easily Scalable Partition Tolerant Tableless / Schemaless Very Fast Example Whitehouse.gov direct engagement 15k/day requests 2M records in db Replication issues since db was nearly 4gb. Switch to MongoDB Relatively easy replication / sharding Now over 180M collections in collection.

Why MongoDB? Cons


Not exactly query-less. Still have to format your query to it correctly. Range query / sort must be based on last column in index. Have a limit of 64 indexes. Cannot join across entities (and thus filter on data from multiple entities). No DBTNG Implementation.

MongoDB Module
http://drupal.org/project/mongodb mongodb: core support library for other modules mongodb_block: Store blocks in mongo mongodb_cache: Cache using mongo mongodb_session: store sessions in mongo mongodb_watchdog: Store watchdog in mongo mongodb_queue: Store queues in mongodb mongodb_field_storage: Store fields in mongodb

MongoDB core
$collection = mongodb_collection($collection_name) $collection->findOne(array('_id' => (string)$nid)); $collection->find($conditions); $collection->remove(array('_type' => 'blah')); $collection->save(array($sanitized_node)); That's really it ^_^

MongoDB Watchdog
Lower strain on db server. Useful when there might be a lot of activity on site (be it good or bad). Can cap collection size. Quick purge. Enable it and you're ready to go (disable dblog - you don't need it).

MongoDB Cache / Sessions


$conf['cache_backends'][] = 'sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc'; $conf['cache_default_class'] = 'DrupalMongoDBCache'; $conf['session_inc'] = 'sites/all/modules/mongodb/mongodb_session/mongodb_session.inc';
Sessions will likely be helpful but cache...not sure what kind of difference is to be seen there. Better off placing efforts in using apc / memcache / something else.

MongoDB Field Storage


Enable MongoDB Field Storage module. $conf['field_storage_default'] = 'mongodb_field_storage'; Biggest gains to site are from this. PROS Faster saving, deletion, node retrieval. Fully compatible with entityfieldquery. No real limits on field lengths (*no image alt length issues) Partial Views Integration through EntityFieldQueryViews (http://drupal.org/project/efq_views) - could use some help

Demo

Questions?
Thank you :)

You might also like