couchdb & ruby: you’re doing it wrong

69
COUCHDB&RubY YOU’REDOINGIT RONG APRESENTATIONBY @timangladE FROMYOURFRIENDSAT @cloudant W

Upload: tim-anglade

Post on 16-May-2015

11.767 views

Category:

Technology


2 download

DESCRIPTION

As giv

TRANSCRIPT

Page 1: CouchDB & Ruby: You’re Doing it Wrong

COUCHDB&RubYYOU’RE!DOING!IT RONG

A!PRESENTATION!BY @timangladEFROM!YOUR!FRIENDS!AT @cloudant

W

Page 2: CouchDB & Ruby: You’re Doing it Wrong

@timanglade

Page 3: CouchDB & Ruby: You’re Doing it Wrong
Page 4: CouchDB & Ruby: You’re Doing it Wrong
Page 5: CouchDB & Ruby: You’re Doing it Wrong
Page 6: CouchDB & Ruby: You’re Doing it Wrong

COUCHDB HOSTING+

AD-HOC SOLUTIONS

Page 7: CouchDB & Ruby: You’re Doing it Wrong

Re:Identical nodes& Dist. Testing

Page 8: CouchDB & Ruby: You’re Doing it Wrong

Ruby:10% OF our USERS65% OF the I/O

That’s called having a vested interest, my Friends

Page 9: CouchDB & Ruby: You’re Doing it Wrong

COUCHDB➞ A SimplE REST STORE

Page 10: CouchDB & Ruby: You’re Doing it Wrong

tim$ curl -X GET https://localhost:5984/nosqlsummer/berlintim$ { _id: "berlin" _rev: "87-d666a8e1176a068b343d7ccca7260141" name: "Berlin" lifeguards: "Tim Lossen" welcome: "What could be a better excuse to hang …" }

Page 11: CouchDB & Ruby: You’re Doing it Wrong

A match madein HEAVEN?

Page 12: CouchDB & Ruby: You’re Doing it Wrong

In Rubyland:COUCHRESTgithub.com/couchrest

Page 13: CouchDB & Ruby: You’re Doing it Wrong

require 'couchrest'

db = CouchRest.database!("https://tim.cloudant.com/nosqlsummer")

db.get("berlin")

=> { "name" => "Berlin", "lifeguards" => "Tim Lossen", "_rev" => "87-d666a8e1176a068b343d7ccca7260141", "welcome" => "What could be a better excuse to hang out …" }

Page 14: CouchDB & Ruby: You’re Doing it Wrong

Looking Good,right?

Page 15: CouchDB & Ruby: You’re Doing it Wrong

0

200

400

600

800

1k 10k 50k 100k

MEDIAN TIME TO SAVE A DOCTi

me

spen

t (m

s)

Document Size

Page 16: CouchDB & Ruby: You’re Doing it Wrong

MAN, COUCHDBIS SO SLOW…

Page 17: CouchDB & Ruby: You’re Doing it Wrong

WRONG WRONG WRONG WRONG

Page 18: CouchDB & Ruby: You’re Doing it Wrong

require 'couchrest'

db = CouchRest.database!("https://tim.cloudant.com/nosqlsummer")

db.get("berlin")

=> { "name" => "Berlin", "lifeguards" => "Tim Lossen", "_rev" => "87-d666a8e1176a068b343d7ccca7260141", "welcome" => "What could be a better excuse to hang out …" }

Page 19: CouchDB & Ruby: You’re Doing it Wrong

Warning #0CouchREST#Database!

VS.CouchREST#Database

upgrade to Couchrest 1.1.3 now

Page 20: CouchDB & Ruby: You’re Doing it Wrong

Warning #1Actually, don’t useMuch of CouchRESTAT ALLYou’LL Thank me later.

Page 21: CouchDB & Ruby: You’re Doing it Wrong

Warning #2Loada proper JSON LIBRARY

MULTI_JSON = fail

Page 22: CouchDB & Ruby: You’re Doing it Wrong

Warning #3LOCALITY

Page 23: CouchDB & Ruby: You’re Doing it Wrong

Warning #4TO HTTPS… OR NOT?

Page 24: CouchDB & Ruby: You’re Doing it Wrong

require 'json/ext'require 'couchrest'@db = "http://tim-east.cloudant.com/mydb"

def my_functionCouchRest.put(@db, doc)

end

require 'couchrest'def my_function db = CouchRest.database!("https://tim-west.cloudant.com/mydb") db.save_doc(doc)def

Before

AFTER

Page 25: CouchDB & Ruby: You’re Doing it Wrong

0

200

400

600

800

1k 10k 50k 100k

BeforeTi

me

spen

t (m

s)

Document Size

EncodingHTTPDecoding

Page 26: CouchDB & Ruby: You’re Doing it Wrong

How Much?

10% ? 20% ? 30% ?

Page 27: CouchDB & Ruby: You’re Doing it Wrong

0

200

400

600

800

1k 10k 50k 100k

BeforeTi

me

spen

t (m

s)

Document Size

EncodingHTTPDecoding

Page 28: CouchDB & Ruby: You’re Doing it Wrong

0

200

400

600

800

1k 10k 50k 100k

Tim

e sp

ent

(ms)

Document Size

EncodingHTTPDecoding

AFTER

Page 29: CouchDB & Ruby: You’re Doing it Wrong

AFTER

0

8

15

23

30

1k 10k 50k 100k

Tim

e sp

ent

(ms)

Document Size

EncodingHTTPDecoding

Page 30: CouchDB & Ruby: You’re Doing it Wrong

Lol96%

AND Guess what, we’re not done yet…

Page 31: CouchDB & Ruby: You’re Doing it Wrong

Warning #5LOLJSON

Page 32: CouchDB & Ruby: You’re Doing it Wrong

MESSAGEPACK

Say Hello to my little FRIEND

Page 33: CouchDB & Ruby: You’re Doing it Wrong
Page 34: CouchDB & Ruby: You’re Doing it Wrong

How complex?10 lines of code

Page 35: CouchDB & Ruby: You’re Doing it Wrong

0

8

15

23

30

1k 10k 50k 100k

With MessagePACK

EncodingHTTPDecodingJSON

3ms

6MS9MS

3ms

Page 36: CouchDB & Ruby: You’re Doing it Wrong

COUCHDB➞ A NOT-SO-SimplE REST STORE

Page 37: CouchDB & Ruby: You’re Doing it Wrong

I SHOULD USE COUCHREST_MODEL,RIGHT?

Page 38: CouchDB & Ruby: You’re Doing it Wrong

WRONG WRONG WRONG WRONG

Page 39: CouchDB & Ruby: You’re Doing it Wrong

ODMs areA BAD IDEA

Page 40: CouchDB & Ruby: You’re Doing it Wrong

COUCHREST_MODEL IS POORLYIMPLEMENTEDFile > Open > nightmare.RB

Page 41: CouchDB & Ruby: You’re Doing it Wrong
Page 42: CouchDB & Ruby: You’re Doing it Wrong
Page 43: CouchDB & Ruby: You’re Doing it Wrong
Page 44: CouchDB & Ruby: You’re Doing it Wrong

DoN’T USECOUCHREST_MODEL

Or I will personally hunt you downand punch you in the neck

Page 45: CouchDB & Ruby: You’re Doing it Wrong

➞ So WHAT?

Page 46: CouchDB & Ruby: You’re Doing it Wrong

GROUP INFOONE HTTP CALL PERRUBY METHOD

Write views as necessaryIF you can’t ➡ Wrong DB?

Page 47: CouchDB & Ruby: You’re Doing it Wrong

{ "_id": "berlin", "country": "Germany", "meetings": { "2010-10-17": { "location": "Beergarden", "description": "Initial meeting. Come say hi!" } "2010-12-27": { "location": "Alexanderplatz", "description": "Second meeting. Yes!" } } }

Page 48: CouchDB & Ruby: You’re Doing it Wrong

LEARN HOW TO USEBULK_DOCS

A no-brainer if you do multiple updatesinSIDE one ruby method

Page 49: CouchDB & Ruby: You’re Doing it Wrong

LEARN VIEWSTHE HARD WAY

Page 50: CouchDB & Ruby: You’re Doing it Wrong

function(doc) { if (doc.type == 'city') { emit(doc.id, doc); }}

MAP

Page 51: CouchDB & Ruby: You’re Doing it Wrong

function(doc) { if (doc.type == 'city') { emit(doc.id, doc['meetings'].length); }}

MAP

REDUCE_stats

Page 52: CouchDB & Ruby: You’re Doing it Wrong

LEARN VIEWSTHE NOT-SO-HARD WAYgithub.com/candlerb/couchdb_ruby_view

Page 53: CouchDB & Ruby: You’re Doing it Wrong

LEARNTO PUT MORE APPLOGIC IN COUCHDB

Page 54: CouchDB & Ruby: You’re Doing it Wrong

LEARNWHEN TO USEFULL-TEXT SEARCHDon’t WRITE A VIEW PER COLUMN-EQUIVALENT…

Page 55: CouchDB & Ruby: You’re Doing it Wrong

LEARNSTALE=OK

COUCHDB VIEW ARE UPDATED on READS.YOU MAY WAIT A WHILE…

Page 56: CouchDB & Ruby: You’re Doing it Wrong

➞ GOD MODE

Page 57: CouchDB & Ruby: You’re Doing it Wrong

CloudantSoftlayer

users

SinatraAPAC

SINATRAUS-EAST

Page 58: CouchDB & Ruby: You’re Doing it Wrong

LEARNTO LEVERAGEREPLICATION

Page 59: CouchDB & Ruby: You’re Doing it Wrong

SinatraAPAC

CloudantAPAC

SINATRAUS-EAST

CloudantUS-East

CloudantSOFTLAYER

users

Page 60: CouchDB & Ruby: You’re Doing it Wrong

LEARNHOW TO TWEAKCONSISTENCY

Page 61: CouchDB & Ruby: You’re Doing it Wrong

SinatraAPAC

CloudantAPAC

SINATRAUS-EAST

CloudantUS-East

CloudantSOFTLAYER

users

Page 62: CouchDB & Ruby: You’re Doing it Wrong

LEARNTO OFFLOADTO FRONT-END JS

Page 63: CouchDB & Ruby: You’re Doing it Wrong

SinatraAPAC

CloudantAPAC

SINATRAUS-EAST

CloudantUS-East

CloudantSOFTLAYER

users

Page 64: CouchDB & Ruby: You’re Doing it Wrong

LEARNTO CACHESOME COUCHDBROUTES

Page 65: CouchDB & Ruby: You’re Doing it Wrong

SinatraAPAC

CloudantAPAC

SINATRAUS-EAST

CloudantUS-East

CloudantSOFTLAYER

CDN

users

Page 66: CouchDB & Ruby: You’re Doing it Wrong

Recap!!1.! NEVER USE COUCHREST_MODEL!2.!Be WARY OF COUCHREST!3.!LOAD A PROPER JSON LIBRARY!4.!PAY ATTENTION TO LOCALITY!5.!ONLY USE HTTPS WHEN NECESSARY!6.!Don’t be afraid to extend

Page 67: CouchDB & Ruby: You’re Doing it Wrong

GoEXPERIMENTIMPLEMENTMEASUREIMPROVEHAVE FUN

Page 69: CouchDB & Ruby: You’re Doing it Wrong

github.com/timanglade

[email protected]

@timanglade

?