NoSQL CGN: CouchDB (11/2011)

1,666 views

Published on

Kleine Einführung in CouchDB auf der NoSQL Usergroup Cologne am 2.11.2011.

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,666
On SlideShare
0
From Embeds
0
Number of Embeds
690
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

NoSQL CGN: CouchDB (11/2011)

  1. 1. Relax! Sebastian Cohnen @tisba / tisba.deMittwoch, 16. November 11
  2. 2. About Me • Freier Entwickler ❤ Ruby/Rails & node.js ❤ Performance & Scalability Engineering ❤ Distributed Load Testing ❤ CouchDB, Redis & Riak und ebenfalls interessiert an Erlang, AMQP, ...Mittwoch, 16. November 11
  3. 3. Users of Couchdb BBC meebo UbuntuOne ... adcloudMittwoch, 16. November 11
  4. 4. CouchDB: Basics Schema-frei Dokumenten-orientiert Key/Value-Speicher fehlertolerant & robustMittwoch, 16. November 11
  5. 5. Key Features HTTP + JSON Multi-Master Replikation AP aus CAP Append-only inkrementelle, materialisierte Views (map/reduce)Mittwoch, 16. November 11
  6. 6. HTTP & JSONMittwoch, 16. November 11
  7. 7. Admin InterfaceMittwoch, 16. November 11
  8. 8. Create A Database $ curl -w%{http_code} -X PUT http://127.0.0.1:5984/test_db ↵ {"ok":true} 201 $ $ curl -w%{http_code} -X GET http://127.0.0.1:5984/test_db ↵ {"db_name":"test_db","doc_count":0,"doc_del_count":0, "update_seq":1,"purge_seq":0, "compact_running":false, "disk_size":16473, "instance_start_time": "1253091887127542","disk_format_version":4} 200 * $ alias curl=curl -w%{http_code} -XMittwoch, 16. November 11
  9. 9. create A Document $ curl POST -d {"hello":"world"} http://127.0.0.1:5984/ test_db ↵ {"ok":true,"id":"67729d5013cf3f8858eb29cb17e5a723","rev":"1-1 5f65339921e497348be384867bb940f"} 201 read $ curl GET http://127.0.0.1:5984/test_db/ 67729d5013cf3f8858eb29cb17e5a723 ↵ {"_id":"67729d5013cf3f8858eb29cb17e5a723","_rev":"1-15f653399 21e497348be384867bb940f","hello":"world"} 200Mittwoch, 16. November 11
  10. 10. update $ curl PUT -d {"_rev":"1-15f65339921e497348be384867bb940f", "hello":"world","message":"about to show CRUD in couch"} http://127.0.0.1:5984/test_db/ 2f41f56816191b94ecbd127151faa242 ↵ {"ok":true,"id":"2f41f56816191b94ecbd127151faa242","rev":"2-2 873c60120aa6dbe2204cd2c1a0e8722"} 201 $ curl GET http://127.0.0.1:5984/test_db/ 2f41f56816191b94ecbd127151faa242 ↵ {"_id":"2f41f56816191b94ecbd127151faa242","_rev":"2-2873c6012 0aa6dbe2204cd2c1a0e8722","hello":"world","message":"about to show CRUD in couch"} 200Mittwoch, 16. November 11
  11. 11. delete $ curl DELETE http://127.0.0.1:5984/test_db/ 67729d5013cf3f8858eb29cb17e5a723? rev=1-15f65339921e497348be384867bb940f ↵ {"ok":true,"id":"67729d5013cf3f8858eb29cb17e5a723","rev":"2-2 d715caed35974bb33de24d1d6c95779"} 200 $ curl GET http://127.0.0.1:5984/test_db/ 67729d5013cf3f8858eb29cb17e5a723 ↵ {"error":"not_found","reason":"deleted"} 404Mittwoch, 16. November 11
  12. 12. CouchApps Dokumente können Attachments haben CouchDB als HTTP Server HTML+CSS+JS ausgeliefert von CouchDB greift via HTTP auf CouchDB als Datenbank zu Beispiel: Kabul War Diary http://upondata.com:5984/afgwar/_design/afgwardiary/ index.htmlMittwoch, 16. November 11
  13. 13. ReplikationMittwoch, 16. November 11
  14. 14. Replikation Replikation läuft via HTTP asynchron inkrementell (online-offline) automatische Konfliktlösung Multi-Version Concurrency Control (MVCC) Multi-Master als default filterbarMittwoch, 16. November 11
  15. 15. Map/Reduce ViewsMittwoch, 16. November 11
  16. 16. Accessing Data direkter Zugriff via http://server/DATABASE/DOC-ID materialisierte Views bestehen aus einer map-Phase und einer optionalen reduce-Phase show & list: (Dokument) Transformationen filters, externals, ...Mittwoch, 16. November 11
  17. 17. Views sortiert, inkrementell, effizienter Zugriff via B-Trees build-in Viewserver: JavaScript (Spidermonkey) Erlang 3rd Party Viewserver in Ruby, Python, Java, Perl, ...Mittwoch, 16. November 11
  18. 18. map/reduce map: Eine Funktion, welche key/value Paare in einen Index schreibt Beispiel Tag-Cloud: 1 function(doc) { 2 if (doc.tags) { 3 for(var idx in doc.tags) { 4 emit(doc.tags[idx], 1); 5 } 6 } 7 }Mittwoch, 16. November 11
  19. 19. map example {“body”:”[...]”, “tags”:[“erlang”, “couchdb”]} {“body”:”[...]”, “tags”:[“couchdb”, “talk”, “rails”]} map-function(doc) {“key”:“couchdb”, “value”:1} {“key”:“couchdb”, “value”:1} {“key”:“erlang”, “value”:1} {“key”:“rails”, “value”:1} {“key”:“talk”, “value”:1} * indices are automatically sortedMittwoch, 16. November 11
  20. 20. map/reduce reduce wird verwendet, um das Ergebnis der map- Phase zu verarbeiten 1 function(keys, values, rereduce) { 2 return sum(values); 3 }Mittwoch, 16. November 11
  21. 21. reduce example {“key”:“erlang”: “value”:1} {“key”:“couchdb”: “value”:1} {“key”:“couchdb”: “value”:1} {“key”:“talk”: “value”:1} {“key”:“rails”: “value”:1} reduce function(...) {"key":"erlang","value":1} {"key":"couchdb","value":2} {"key":"talk","value":1} {"key":"rails","value":1}Mittwoch, 16. November 11
  22. 22. CouchDB: Pros HTTP (Proxy, Caches, Loadbalancer, ...) HTTP (CouchDB als Webserver, 2-tier Apps!) Replikation Views sind sortiert; effizienter Zugriff auf RangesMittwoch, 16. November 11
  23. 23. Cons Append-only erfordert Compaction Append-only & MVCC/Konfliktlösung führen zu Probleme bei Update-heavy Anwendungen keine verteilte Datenbank (sharding, clustering)Mittwoch, 16. November 11
  24. 24. Get it! http://couchdb.apache.org/downloads.html brew install couchdb / apt-get install couchdb / ... freies Hosting: www.iriscouch.com BigCouch (cloudant.com / https://github.com/cloudant/bigcouch) dynamo-style CouchDB Cluster Couchbase (www.couchbase.com) Membase+CouchDBMittwoch, 16. November 11
  25. 25. Thanks! Q & A? ? Sebastian Cohnen @tisbaMittwoch, 16. November 11
  26. 26. Understanding reduce 1 function(keys, values, rereduce) {} a b c d | e f g h | i j k l | m n 1 2 1 3 | 1 2 3 1 | 2 3 3 1 | 1 8 7 7 | 9 9 14 18 32 function( [[“a”,id1],[“b”,id2],[“c”,id3],[“d”,id4]], [1, 2, 1, 3], false) {...} function(null, [ 7, 7], true) {...} function(null, [ 9, 9], true) {...} function(null, [14,18], true) {...}Mittwoch, 16. November 11

×