Non-Relational Databases

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Non-Relational Databases - Presentation Transcript

    1. Non-Relational Databases
      San Francisco Perl Mongers
      Kristina Chodorow
      September 3, 2009
    2. Who am I?
      Software Engineer at 10gen
      Perl, PHP, Java drivers
    3. Scaling
    4. Scaling
    5. Technique #1:
      literally scale
    6. Technique #1:
      literally scale
      (Courtesy of Ask Bjorn Hansen)
      $3,200
      $4,000,000
      x 1250 =
    7. Technique #2: shard
      now-yesterday
      yesterday-
      the day before
      the day before-
      the day before that
    8. Technique #3: master-slave replication
      R
      W
      W
      R/W?
      W
      R
    9. Cassandra
      Designed by Facebook
      Distributed - eventually consistent
      Column-oriented
    10. Cassandra
      Writes ALWAYS work
      Two types of reads:
      high performance
      guaranteed correct
      R/W atomic within column family
    11. Cassandra
      Row-oriented:
      joe, 34, karen, 25, bob, 50
      Column-oriented:
      joe, karen, bob, 34, 25, 50
    12. Project Voldemort
      Key/value store
      Automatic replication/partitioning
      75 Github forks
      “It is basically a just a big, distributed, persistent, fault-tolerant hash table.”
    13. Tokyo Cabinet
      Another key/value store
      Blazing fast… theoretically
      Lua for server-side scripting
    14. Tokyo Cabinet
      Key/value pairs
      Array store
      Index-able Hash
      {
      name : “Chris”
      age : 27,
      DOB : “January 1”
      }
    15. CouchDB
      Master-Master Replication
      Map/Reduce
      REST API
    16. CouchDB Futon
    17. MongoDB
    18. MongoDB
      Ease of use
      Scalable
      Dynamic queries - similar “feel” to SQL
      Speed of key/value stores (almost)
      Power of RDBMSs (almost)
    19. The Perl Driver
      Available at Github:
      www.github.com/mongodb/mongo-perl-driver/
      Install the Perl driver
      $ perl Makefile.PL && sudo make install
      Available on CPAN (but old):
      http://search.cpan.org/~flora/MongoDB-0.01/
    20. Downloading MongoDB
      www.mongodb.org
      Binaries available for Linux, Mac, Windows, Solaris
    21. Start the DB Server
      $ mkdir ~/db
      $
      $ tar zxvfmongodb-<OS>-1.0.0.tgz
      $ cdmongodb-<OS>-1.0.0
      $ bin/mongod --dbpath ~/db
    22. Connecting to the Database
      use MongoDB;
      my $connection = MongoDB::Connection->new;
      my $db = $connection->get_database(‘test’);
      my $collection = $db->get_collection(‘foo’);
    23. Inserting
      my $id = $collection->insert(
      {
      title => ‘My first blog post’,
      author => ‘Joe’,
      content => ‘Hello, world!’
      comments => []
      }
      );
    24. MongoDB::OID
      an autogenerated primary key
      my $id = $collection->insert({whatever});
      print Dumper($id);
      --------------------------------------------
      $VAR1 = bless( { 'value' => '4a9700dba5f9107c5cbc9a9c' }, 'MongoDB::OID' )
    25. Updating
      $collection->update({_id => $id},
      {‘$push’ => {comments =>
      {
      ‘author’ => ‘Fred’,
      ‘comment’ => ‘Dumb post.”
      }
      }});
    26. …which gives us:
      print Dumper($collection->find_one());
      --------------------------------------------
      {
      title : ‘My first blog post’,
      author : ‘Joe’,
      content : ‘Hello, world!’
      comments : [{
      ‘author’ : ‘Fred’,
      ‘comment’ : ‘Dumb post’
      }]
      }
    27. Magic (not the Perl kind)
      $gt, $gte, $lt, $lte, $eq, $neq, $exists,
      $set, $mod, $where, $in, $nin, $inc
      $push, $pull, $pop, $pushAll, $popAll
      $c->query({ x => {‘$gt’ => 4}})
    28. Querying
      my $commented_by_fred =
      $collection->query({
      “comments.author” : “Fred”
      });
      my $commented_by_fred =
      $collection->query({
      “comments.author” : qr/fred/i
      });
    29. $where
      $collection->find_one({‘$where’ :
      ‘this.y == (this.x + this.z)’});
      Will work:
      {x => 1, y => 4, z => 3}
      {x => “hi”, y => “hibye”, z => “bye”}
      Won’t work:
      {x => 1, y => 1}
    30. Optimizing $where
      $collection->find_one({
      ‘name’ => ‘Sally’,
      ‘age’ => {‘$gt’ => 18},
      ‘$where’ => ‘Array.sort(this.interests)[2] == “volleyball”’});
    31. Speaking of indexing…
      $collection->ensure_index({“age” => “ascending”});
      $collection->ensure_index({
      “name” => “descending”,
      “ts” => “descending”,
      “comments.author” => “ascending”
      });
    32. Cursors
      my $cursor = $coll->query({“foo” => “bar”});
      my $obj;
      while (my $obj = $cursor->next) {
      ...
      }
      my @all = $cursor->all;
    33. Paging
      my $cursor = $coll->query->
      sort({ts => -1})->
      skip($page_num * $results_per_page)->
      limit($results_per_page);
      my @page = $cursor->all;
    34. Logging
      insert/update/remove is fast
      Capped collections
      Schemaless
      $inc for counts
    35. Thank you!
      kristina@10gen.com
      @kchodorow
      @mongodb
      irc.freenode.net#mongodb
      www.mongodb.org
    SlideShare Zeitgeist 2009

    + kchodorowkchodorow Nominate

    custom

    434 views, 0 favs, 0 embeds more stats

    San Francisco Perl Mongers presentation, September more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 434
      • 434 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 12
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories