CouchDB & Ruby: You’re Doing it Wrong
Upcoming SlideShare
Loading in...5
×
 

CouchDB & Ruby: You’re Doing it Wrong

on

  • 11,263 views

As giv

As giv

Statistics

Views

Total Views
11,263
Views on SlideShare
11,007
Embed Views
256

Actions

Likes
20
Downloads
66
Comments
0

10 Embeds 256

http://lanyrd.com 98
http://blog.yougom.com 68
http://cliveboulton.com 58
https://twitter.com 16
http://yougome.tistory.com 6
http://www.hanrss.com 4
http://www.linkedin.com 3
http://safe.tumblr.com 1
http://us-w1.rockmelt.com 1
http://safe.txmblr.com 1
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

CouchDB & Ruby: You’re Doing it Wrong CouchDB & Ruby: You’re Doing it Wrong Presentation Transcript

  • COUCHDB&RubYYOU’RE DOING ITWRONGA PRESENTATION BY @timangladEFROM YOUR FRIENDS AT @cloudant
  • @timanglade
  • COUCHDB HOSTING +AD-HOC SOLUTIONS
  • Re:Identical nodes& Dist. Testing
  • Ruby:10% OF our USERS65% OF the I/OThat’s called having a vested interest, my Friends
  • COUCHDB➞ A SimplE REST STORE
  • 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 …" }
  • A match madein HEAVEN?
  • In Rubyland:COUCHRESTgithub.com/couchrest
  • require couchrestdb = 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 …" }
  • Looking Good,right?
  • MEDIAN TIME TO SAVE A DOC 800 600Time spent (ms) 400 200 0 1k 10k 50k 100k Document Size
  • MAN, COUCHDBIS SO SLOW…
  • WRONGWRONGWRONG
  • require couchrestdb = 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 …" }
  • Warning #0CouchREST#Database! VS.CouchREST#Databaseupgrade to Couchrest 1.1.3 now
  • Warning #1Actually, don’t useMuch of CouchRESTAT ALLYou’LL Thank me later.
  • Warning #2Loada proper JSON LIBRARYMULTI_JSON = fail
  • Warning #3LOCALITY
  • Warning #4TO HTTPS… OR NOT?
  • Beforerequire couchrestdef my_function db = CouchRest.database!("https://tim-west.cloudant.com/mydb") db.save_doc(doc)defAFTERrequire json/extrequire couchrest@db = "http://tim-east.cloudant.com/mydb"def my_function CouchRest.put(@db, doc)end
  • Before 800 Decoding HTTP Encoding 600Time spent (ms) 400 200 0 1k 10k 50k 100k Document Size
  • How Much?10% ? 20% ? 30% ?
  • Before 800 Decoding HTTP Encoding 600Time spent (ms) 400 200 0 1k 10k 50k 100k Document Size
  • AFTER 800 Decoding HTTP Encoding 600Time spent (ms) 400 200 0 1k 10k 50k 100k Document Size
  • AFTER 30 Decoding HTTP Encoding 23Time spent (ms) 15 8 0 1k 10k 50k 100k Document Size
  • Lol96%AND Guess what, we’re not done yet…
  • Warning #5LOLJSON
  • MESSAGEPACKSay Hello to my little FRIEND
  • How complex?10 lines of code
  • With MessagePACK30 JSON Decoding HTTP Encoding2315 8 9MS 6MS 3ms 3ms0 1k 10k 50k 100k
  • COUCHDB➞ A NOT-SO-SimplE REST STORE
  • I SHOULD USECOUCHREST_MODEL,RIGHT?
  • WRONGWRONGWRONG
  • ODMs areA BAD IDEA
  • COUCHREST_MODELIS POORLYIMPLEMENTEDFile > Open > nightmare.RB
  • DoN’T USECOUCHREST_MODELOr I will personally hunt you downand punch you in the neck
  • ➞ So WHAT?
  • GROUP INFOONE HTTP CALL PERRUBY METHODWrite views as necessaryIF you can’t ➡ Wrong DB?
  • { "_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!" } }}
  • LEARN HOW TO USEBULK_DOCSA no-brainer if you do multiple updatesinSIDE one ruby method
  • LEARN VIEWSTHE HARD WAY
  • MAPfunction(doc) { if (doc.type == city) { emit(doc.id, doc); }}
  • MAPfunction(doc) { if (doc.type == city) { emit(doc.id, doc[meetings].length); }}REDUCE_stats
  • LEARN VIEWSTHE NOT-SO-HARDWAYgithub.com/candlerb/couchdb_ruby_view
  • LEARNTO PUT MORE APPLOGIC IN COUCHDB
  • LEARNWHEN TO USEFULL-TEXT SEARCHDon’t WRITE A VIEW PER COLUMN-EQUIVALENT…
  • LEARNSTALE=OKCOUCHDB VIEW ARE UPDATED on READS.YOU MAY WAIT A WHILE…
  • ➞ GOD MODE
  • Cloudant SoftlayerSinatra SINATRA APAC US-EAST users
  • LEARNTO LEVERAGEREPLICATION
  • Cloudant SOFTLAYERSinatra Cloudant Cloudant SINATRA APAC APAC US-East US-EAST users
  • LEARNHOW TO TWEAKCONSISTENCY
  • Cloudant SOFTLAYERSinatra Cloudant Cloudant SINATRA APAC APAC US-East US-EAST users
  • LEARNTO OFFLOADTO FRONT-END JS
  • Cloudant SOFTLAYERSinatra Cloudant Cloudant SINATRA APAC APAC US-East US-EAST users
  • LEARNTO CACHESOME COUCHDBROUTES
  • Cloudant SOFTLAYER CDNSinatra Cloudant Cloudant SINATRA APAC APAC US-East US-EAST users
  • 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! !
  • GoEXPERIMENTIMPLEMENTMEASUREIMPROVEHAVE FUN
  • Free plan Open Sourcecloudant.com github.com /cloudant/bigcouch BigCouch
  • ? cloudant.com tim@cloudant.comgithub.com/timanglade @timanglade