Successfully reported this slideshow.
BDhcuoC
Who’s talking?

         Jan Lehnardt
         CouchDB Developer
         jan@apache.org


And you?
Who hasn't seen previo...
Number Bragging
 Silly read-only benchmark with
 memory saturation
 2,500 req/s sustained on a
 2Ghz dual core Athlon
Number Bragging
 Silly read-only benchmark with
 memory saturation
 2,500 req/s sustained on a
 2Ghz dual core Athlon
 Usi...
Views
of Keys and Values
Views — Map Tags
              Keys     Values
             family      1
             friends     1
             friends ...
Views — Reduce Tag Count
 Keys     Values    Keys     Values
family      1
                   family      1
friends     1
...
Views — Map Tags


function (doc) {
  for(var i in doc.tags)
    emit(doc.tags[i], 1);
}
Views — Reduce Tag Count
 Keys     Values    Keys     Values
family      1
                   family      1
friends     1
...
Views — Reduce Tag Count

     function (key, values)
     {
       var sum = 0;
       for(var i in values)
         sum ...
View Examples – Docs by Date


function(doc) {
  emit(doc.date, doc.amount);
}


  [2007, 10, 12, 20, 13, 12]   3000
View Examples – Docs by Date
                 Map

           Key               Value

[2007, 10, 12, 20, 13, 12]   3000

...
View Examples – Docs by Date


function(key, values) {
  return sum(values);
}
View Examples – Docs by Date
               Reduce

        Key             Value

        null            15000
View Examples – Docs by Date
    Reduce with group_level = 1

         Key                  Value

        [2007]         ...
View Examples – Docs by Date
                  Reduce with group_level = 2

                              Key             ...
Relation(ship)s
http://flickr.com/photos/fazen
Relation(ship)s
 JOINs please!
 What for?
 Get data that “belongs
 together”
Relation(ship)s — One Big Doc
{
    "type": "person",
    "name": "Darth Vader",
    "children":[
      {"name": "Luke"......
Relation(ship)s — One Big Doc


           Pros: Easy – Cons: Bad with
           concurrent updates
           Use for: L...
Relation(ship)s — Master-
Slave Docs
 Cons: A little more complex –
 Pros: Fast; good with
 concurrent updates; gives you
...
Relation(ship)s
function(doc) {
  if(doc.is_master) {
    emit([doc._id, doc.date], doc);
  } else {
    emit([doc.master_...
Relation(ship)s
                        ...              ...
  ["BAAC67", "2008-09-21"]        {"is_parent",true}
  ["BAAC...
Where is my auto_increment
 What is auto_increment?
 Unique identifier
 Sequence denominator
Where is my auto_increment?




what's it used for? identification, sequences / sorting
location prefixes, datacenters, digg...
Where is my auto_increment?
        Documents have _ids




what's it used for? identification, sequences / sorting
locatio...
Where is my auto_increment?
        Documents have _ids
         Sequences in distributed
         databases are…




what...
Where is my auto_increment?
        Documents have _ids
         Sequences in distributed
         databases are…
        ...
Where is my auto_increment?
        Documents have _ids
         Sequences in distributed
         databases are…
        ...
Transactions
 Run multiple operations at
 once
 They all succeed or none gets
 applied
Transactions
POST
{
  "docs": [
    {"_id": "0", "int": 0, "str": "0"},
    {"_id": "1", "int": 1, "str": "1"},
    {"_id"...
Transactions — Watch out
 Statement transaction, not
 data transaction
 No roundtripping
 No multi-node transactions
 (It'...
Multi-Node Transactions
 Why? – Data redundancy
 Use an HTTP proxy
 Nice and easy to build on
 standard protocols
 Project...
Architectures
periodic, notifier system
P2P apps
Hot backup?



 POSIX compliant
Hot backup?



$ cp -r /var/lib/couchdb/* 
  /mnt/backup
Commercial Break
The Book

O'Reilly
http://books.couchdb.org/relax
Apache 2.0 Licensed
Summer 2009
The Book —Can’t wait?

 Help CouchDB
 Hire me for Consulting,
 Training, Development
 jan@apache.org
Resources
        Twitter: @CouchDB & http://couchdb.org/
        Dress like a Couch:
        http://shop.couchdb.com
    ...
Thank You
Really, thanks.
Got it?
Questions
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Jan Lehnardt Couch Db In A Real World Setting
Upcoming SlideShare
Loading in …5
×

Jan Lehnardt Couch Db In A Real World Setting

822 views

Published on

  • Be the first to comment

Jan Lehnardt Couch Db In A Real World Setting

  1. 1. BDhcuoC
  2. 2. Who’s talking? Jan Lehnardt CouchDB Developer jan@apache.org And you? Who hasn't seen previous talk? Joe's Talk? Tim's?
  3. 3. Number Bragging Silly read-only benchmark with memory saturation 2,500 req/s sustained on a 2Ghz dual core Athlon
  4. 4. Number Bragging Silly read-only benchmark with memory saturation 2,500 req/s sustained on a 2Ghz dual core Athlon Using 9.8 MB RAM
  5. 5. Views of Keys and Values
  6. 6. Views — Map Tags Keys Values family 1 friends 1 friends 1 work 1 work 1 youtube 1 … …
  7. 7. Views — Reduce Tag Count Keys Values Keys Values family 1 family 1 friends 1 friends 1 friends 2 work 1 work 2 work 1 youtube 1 youtube 1 … … … …
  8. 8. Views — Map Tags function (doc) { for(var i in doc.tags) emit(doc.tags[i], 1); }
  9. 9. Views — Reduce Tag Count Keys Values Keys Values family 1 family 1 friends 1 friends 1 friends 2 work 1 work 2 work 1 youtube 1 youtube 1 … … … …
  10. 10. Views — Reduce Tag Count function (key, values) { var sum = 0; for(var i in values) sum += values[i]; return sum; } Incremental, On-demand reduce optional
  11. 11. View Examples – Docs by Date function(doc) { emit(doc.date, doc.amount); } [2007, 10, 12, 20, 13, 12] 3000
  12. 12. View Examples – Docs by Date Map Key Value [2007, 10, 12, 20, 13, 12] 3000 [2007, 10, 26, 08, 37, 55] 4000 [2008, 02, 03, 10, 22, 34] 2000 [2008, 05, 01, 14, 16, 11] 6000
  13. 13. View Examples – Docs by Date function(key, values) { return sum(values); }
  14. 14. View Examples – Docs by Date Reduce Key Value null 15000
  15. 15. View Examples – Docs by Date Reduce with group_level = 1 Key Value [2007] 7000 [2008] 8000
  16. 16. View Examples – Docs by Date Reduce with group_level = 2 Key Value [2007, 10] 7000 [2008, 02] 2000 [2008, 05] 6000 Just the beginning, knock yourself out, averages, standard deviation, jchris twitter tag cloud ranking.
  17. 17. Relation(ship)s http://flickr.com/photos/fazen
  18. 18. Relation(ship)s JOINs please! What for? Get data that “belongs together”
  19. 19. Relation(ship)s — One Big Doc { "type": "person", "name": "Darth Vader", "children":[ {"name": "Luke"...}, {"name": "Leia"...} ], "dark_side": true }
  20. 20. Relation(ship)s — One Big Doc Pros: Easy – Cons: Bad with concurrent updates Use for: Low volume updates e.g. user-supplied tags, postings
  21. 21. Relation(ship)s — Master- Slave Docs Cons: A little more complex – Pros: Fast; good with concurrent updates; gives you tree operations Use for: Everything else
  22. 22. Relation(ship)s function(doc) { if(doc.is_master) { emit([doc._id, doc.date], doc); } else { emit([doc.master_id, doc.date], doc); } }
  23. 23. Relation(ship)s ... ... ["BAAC67", "2008-09-21"] {"is_parent",true} ["BAAC67", "2008-09-22"] {"...","..."} ["BAAC67", "2008-09-23"] {"...","..."} ["BAAC67", "2008-09-24"] {"...","..."} ["DBCA82", "2008-09-21"] {"is_parent",true} ... ... arbitrary trees, deeper nesting
  24. 24. Where is my auto_increment What is auto_increment? Unique identifier Sequence denominator
  25. 25. Where is my auto_increment? what's it used for? identification, sequences / sorting location prefixes, datacenters, digg, facebook
  26. 26. Where is my auto_increment? Documents have _ids what's it used for? identification, sequences / sorting location prefixes, datacenters, digg, facebook
  27. 27. Where is my auto_increment? Documents have _ids Sequences in distributed databases are… what's it used for? identification, sequences / sorting location prefixes, datacenters, digg, facebook
  28. 28. Where is my auto_increment? Documents have _ids Sequences in distributed databases are… …not what's it used for? identification, sequences / sorting location prefixes, datacenters, digg, facebook
  29. 29. Where is my auto_increment? Documents have _ids Sequences in distributed databases are… …not Use natural keys what's it used for? identification, sequences / sorting location prefixes, datacenters, digg, facebook
  30. 30. Transactions Run multiple operations at once They all succeed or none gets applied
  31. 31. Transactions POST { "docs": [ {"_id": "0", "int": 0, "str": "0"}, {"_id": "1", "int": 1, "str": "1"}, {"_id": "2", "int": 2, "str": "2"} ] }
  32. 32. Transactions — Watch out Statement transaction, not data transaction No roundtripping No multi-node transactions (It's a good thing)
  33. 33. Multi-Node Transactions Why? – Data redundancy Use an HTTP proxy Nice and easy to build on standard protocols Projects in development for consistent hashing & Paxos
  34. 34. Architectures
  35. 35. periodic, notifier system
  36. 36. P2P apps
  37. 37. Hot backup? POSIX compliant
  38. 38. Hot backup? $ cp -r /var/lib/couchdb/* /mnt/backup
  39. 39. Commercial Break
  40. 40. The Book O'Reilly http://books.couchdb.org/relax Apache 2.0 Licensed Summer 2009
  41. 41. The Book —Can’t wait? Help CouchDB Hire me for Consulting, Training, Development jan@apache.org
  42. 42. Resources Twitter: @CouchDB & http://couchdb.org/ Dress like a Couch: http://shop.couchdb.com http://damienkatz.net/ & http://jan.prima.de/ http://blog.racklabs.com/?p=74 https://peepcode.com/products/couchdb- with-rails not covered everything, other talks + tutorials
  43. 43. Thank You Really, thanks.
  44. 44. Got it? Questions

×