Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB and Drupal - Drupal in LA Feb 2012

btmash
February 07, 2012

MongoDB and Drupal - Drupal in LA Feb 2012

MongoDB and Drupal presented to the Los Angeles High Performance Meetup group in February 2012

btmash

February 07, 2012
Tweet

More Decks by btmash

Other Decks in Technology

Transcript

  1. 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
  2. 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.
  3. 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_" } ...
  4. 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});
  5. 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.
  6. 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.
  7. 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
  8. 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).
  9. 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.
  10. 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