53
CouchDB

Jan Lehnardt Couch Db In A Real World Setting

Embed Size (px)

Citation preview

Page 1: Jan Lehnardt Couch Db In A Real World Setting

CouchDB

Page 2: Jan Lehnardt Couch Db In A Real World Setting

Who’s talking?

Jan Lehnardt

CouchDB Developer

[email protected]

And you?Who hasn't seen previous talk? Joe's Talk? Tim's?

Page 3: Jan Lehnardt Couch Db In A Real World Setting

Number Bragging

Silly read-only benchmark with memory saturation

2,500 req/s sustained on a 2Ghz dual core Athlon

Page 4: Jan Lehnardt Couch Db In A Real World Setting

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

Page 5: Jan Lehnardt Couch Db In A Real World Setting

Viewsof Keys and Values

Page 6: Jan Lehnardt Couch Db In A Real World Setting

Views — Map Tags

Keys Values

family 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Page 7: Jan Lehnardt Couch Db In A Real World Setting

Views — Reduce Tag Count

Keys Values

family 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Keys Values

family 1

friends 2

work 2

youtube 1

… …

Page 8: Jan Lehnardt Couch Db In A Real World Setting

Views — Map Tags

function (doc) { for(var i in doc.tags) emit(doc.tags[i], 1);}

Page 9: Jan Lehnardt Couch Db In A Real World Setting

Views — Reduce Tag Count

Keys Values

family 1

friends 1

friends 1

work 1

work 1

youtube 1

… …

Keys Values

family 1

friends 2

work 2

youtube 1

… …

Page 10: Jan Lehnardt Couch Db In A Real World Setting

Views — Reduce Tag Count

function (key, values){ var sum = 0; for(var i in values) sum += values[i]; return sum;}

Incremental, On-demandreduce optional

Page 11: Jan Lehnardt Couch Db In A Real World Setting

View Examples – Docs by Date

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

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

Page 12: Jan Lehnardt Couch Db In A Real World Setting

View Examples – Docs by Date

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

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

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

Page 13: Jan Lehnardt Couch Db In A Real World Setting

View Examples – Docs by Date

function(key, values) { return sum(values);}

Page 14: Jan Lehnardt Couch Db In A Real World Setting

View Examples – Docs by Date

Key Value

null 15000

Reduce

Page 15: Jan Lehnardt Couch Db In A Real World Setting

View Examples – Docs by Date

Key Value

[2007] 7000

[2008] 8000

Reduce with group_level = 1

Page 16: Jan Lehnardt Couch Db In A Real World Setting

View Examples – Docs by Date

Key Value

[2007, 10] 7000

[2008, 02] 2000

[2008, 05] 6000

Reduce with group_level = 2

Just the beginning, knock yourself out, averages, standard deviation, jchris twitter tag cloud ranking.

Page 17: Jan Lehnardt Couch Db In A Real World Setting

Relation(ship)shttp://flickr.com/photos/fazen

Page 18: Jan Lehnardt Couch Db In A Real World Setting

Relation(ship)s

JOINs please!

What for?

Get data that “belongs together”

Page 19: Jan Lehnardt Couch Db In A Real World Setting

Relation(ship)s — One Big Doc

{ "type": "person", "name": "Darth Vader","children":[ {"name": "Luke"...}, {"name": "Leia"...}],

"dark_side": true}

Page 20: Jan Lehnardt Couch Db In A Real World Setting

Relation(ship)s — One Big Doc

Pros: Easy – Cons: Bad with concurrent updates

Use for: Low volume updates

e.g. user-supplied tags, postings

Page 21: Jan Lehnardt Couch Db In A Real World Setting

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

Page 22: Jan Lehnardt Couch Db In A Real World Setting

Relation(ship)s

function(doc) { if(doc.is_master) { emit([doc._id, doc.date], doc); } else { emit([doc.master_id, doc.date], doc); }}

Page 23: Jan Lehnardt Couch Db In A Real World Setting

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

Page 24: Jan Lehnardt Couch Db In A Real World Setting

Where is my auto_increment

What is auto_increment?

Unique identifier

Sequence denominator

Page 25: Jan Lehnardt Couch Db In A Real World Setting

Where is my auto_increment?

what's it used for? identification, sequences / sortinglocation prefixes, datacenters, digg, facebook

Page 26: Jan Lehnardt Couch Db In A Real World Setting

Where is my auto_increment?

Documents have _ids

what's it used for? identification, sequences / sortinglocation prefixes, datacenters, digg, facebook

Page 27: Jan Lehnardt Couch Db In A Real World Setting

Where is my auto_increment?

Documents have _ids

Sequences in distributed databases are…

what's it used for? identification, sequences / sortinglocation prefixes, datacenters, digg, facebook

Page 28: Jan Lehnardt Couch Db In A Real World Setting

Where is my auto_increment?

Documents have _ids

Sequences in distributed databases are…

…not

what's it used for? identification, sequences / sortinglocation prefixes, datacenters, digg, facebook

Page 29: Jan Lehnardt Couch Db In A Real World Setting

Where is my auto_increment?

Documents have _ids

Sequences in distributed databases are…

…not

Use natural keys

what's it used for? identification, sequences / sortinglocation prefixes, datacenters, digg, facebook

Page 30: Jan Lehnardt Couch Db In A Real World Setting

Transactions

Run multiple operations at once

They all succeed or none gets applied

Page 31: Jan Lehnardt Couch Db In A Real World Setting

Transactions

{ "docs": [ {"_id": "0", "int": 0, "str": "0"}, {"_id": "1", "int": 1, "str": "1"}, {"_id": "2", "int": 2, "str": "2"} ]}

POST

Page 32: Jan Lehnardt Couch Db In A Real World Setting

Transactions — Watch out

Statement transaction, not data transaction

No roundtripping

No multi-node transactions (It's a good thing)

Page 33: Jan Lehnardt Couch Db In A Real World Setting

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

Page 34: Jan Lehnardt Couch Db In A Real World Setting

Architectures

Page 35: Jan Lehnardt Couch Db In A Real World Setting
Page 36: Jan Lehnardt Couch Db In A Real World Setting
Page 37: Jan Lehnardt Couch Db In A Real World Setting
Page 38: Jan Lehnardt Couch Db In A Real World Setting
Page 39: Jan Lehnardt Couch Db In A Real World Setting
Page 40: Jan Lehnardt Couch Db In A Real World Setting
Page 41: Jan Lehnardt Couch Db In A Real World Setting
Page 42: Jan Lehnardt Couch Db In A Real World Setting

periodic, notifier system

Page 43: Jan Lehnardt Couch Db In A Real World Setting
Page 44: Jan Lehnardt Couch Db In A Real World Setting

P2P apps

Page 45: Jan Lehnardt Couch Db In A Real World Setting

Hot backup?

POSIX compliant

Page 46: Jan Lehnardt Couch Db In A Real World Setting

Hot backup?

$ cp -r /var/lib/couchdb/* \ /mnt/backup

Page 47: Jan Lehnardt Couch Db In A Real World Setting

Commercial Break

Page 48: Jan Lehnardt Couch Db In A Real World Setting

The Book

O'Reilly

http://books.couchdb.org/relax

Apache 2.0 Licensed

Summer 2009

Page 49: Jan Lehnardt Couch Db In A Real World Setting

The Book —Can’t wait?

Help CouchDB

Hire me for Consulting, Training, Development

[email protected]

Page 50: Jan Lehnardt Couch Db In A Real World Setting

ResourcesTwitter: @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

Page 51: Jan Lehnardt Couch Db In A Real World Setting

Thank YouReally, thanks.

Page 52: Jan Lehnardt Couch Db In A Real World Setting

Got it?Questions

Page 53: Jan Lehnardt Couch Db In A Real World Setting