Slide 1

Slide 1 text

Drupal and MongoDB High Performance Meetup - LA February 2012 BTMash

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

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_" } ...

Slide 5

Slide 5 text

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});

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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 ^_^

Slide 10

Slide 10 text

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).

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Demo

Slide 14

Slide 14 text

Questions? Thank you :)