Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CouchDB & Ruby - You're doing it wrong
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
gogaruco
September 27, 2011
300
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CouchDB & Ruby - You're doing it wrong
by Tim Anglade
gogaruco
September 27, 2011
More Decks by gogaruco
See All by gogaruco
Wesley Beary at GoGaRuCo 2011
gogaruco
2
68
Ruby Javascript and the Mobile Web
gogaruco
1
93
KidsRuby: Think of the Children
gogaruco
1
170
Smalltalk on Rubinius
gogaruco
1
68
Writing your own Programming Language to Understand Ruby better
gogaruco
3
100
Go for the Rubyist
gogaruco
3
270
Fast Rails Tests
gogaruco
1
180
Featured
See All Featured
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
250
Testing 201, or: Great Expectations
jmmastey
46
8.3k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
240
How to Ace a Technical Interview
jacobian
281
24k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
550
Optimizing for Happiness
mojombo
378
71k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Accessibility Awareness
sabderemane
1
220
Designing for Performance
lara
611
70k
エンジニアに許された特別な時間の終わり
watany
109
250k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
430
Transcript
COUCHDB&RubY YOU’RE DOING IT RONG A PRESENTATION BY @timangladE FROM
YOUR FRIENDS AT @cloudant W
@timanglade
None
None
None
COUCHDB HOSTING + AD-HOC SOLUTIONS
Re: Identical nodes & Dist. Testing
Ruby: 10% OF our USERS 65% OF the I/O That’s
called having a vested interest, my Friends
COUCHDB ➞ A SimplE REST STORE
tim$ curl -X GET https://localhost:5984/nosqlsummer/berlin tim$ { _id: "berlin" _rev:
"87-d666a8e1176a068b343d7ccca7260141" name: "Berlin" lifeguards: "Tim Lossen" welcome: "What could be a better excuse to hang …" }
A match made in HEAVEN?
In Rubyland: COUCHREST github.com/couchrest
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 …" }
Looking Good, right?
0 200 400 600 800 1k 10k 50k 100k MEDIAN
TIME TO SAVE A DOC Time spent (ms) Document Size
MAN, COUCHDB IS SO SLOW…
WRONG WRONG 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 …" }
Warning #0 CouchREST#Database! VS. CouchREST#Database upgrade to Couchrest 1.1.3 now
Warning #1 Actually, don’t use Much of CouchREST AT ALL
You’LL Thank me later.
Warning #2 Load a proper JSON LIBRARY MULTI_JSON = fail
Warning #3 LOCALITY
Warning #4 TO HTTPS… OR NOT?
require 'json/ext' require 'couchrest' @db = "http://tim-east.cloudant.com/mydb" def my_function CouchRest.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
0 200 400 600 800 1k 10k 50k 100k Before
Time spent (ms) Document Size Encoding HTTP Decoding
How Much? 10% ? 20% ? 30% ?
0 200 400 600 800 1k 10k 50k 100k Before
Time spent (ms) Document Size Encoding HTTP Decoding
0 200 400 600 800 1k 10k 50k 100k Time
spent (ms) Document Size Encoding HTTP Decoding AFTER
AFTER 0 8 15 23 30 1k 10k 50k 100k
Time spent (ms) Document Size Encoding HTTP Decoding
Lol96% AND Guess what, we’re not done yet…
Warning #5 LOLJSON
MESSAGEPACK Say Hello to my little FRIEND
None
How complex? 10 lines of code
0 8 15 23 30 1k 10k 50k 100k With
MessagePACK Encoding HTTP Decoding JSON 3ms 6MS 9MS 3ms
COUCHDB ➞ A NOT-SO-SimplE REST STORE
I SHOULD USE COUCHREST_MODEL, RIGHT?
WRONG WRONG WRONG
ODMs are A BAD IDEA
COUCHREST_MODEL IS POORLY IMPLEMENTED File > Open > nightmare.RB
None
None
None
DoN’T USE COUCHREST_MODEL Or I will personally hunt you down
and punch you in the neck
➞ So WHAT?
GROUP INFO ONE HTTP CALL PER RUBY METHOD Write views
as necessary IF 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 USE BULK_DOCS A no-brainer if you do
multiple updates inSIDE one ruby method
LEARN VIEWS THE HARD WAY
function(doc) { if (doc.type == 'city') { emit(doc.id, doc); }
} MAP
function(doc) { if (doc.type == 'city') { emit(doc.id, doc['meetings'].length); }
} MAP REDUCE _stats
LEARN VIEWS THE NOT-SO-HARD WAY github.com/candlerb/couchdb_ruby_view
LEARN TO PUT MORE APP LOGIC IN COUCHDB
LEARN WHEN TO USE FULL-TEXT SEARCH Don’t WRITE A VIEW
PER COLUMN-EQUIVALENT…
LEARN STALE=OK COUCHDB VIEW ARE UPDATED on READS. YOU MAY
WAIT A WHILE…
➞ GOD MODE
Cloudant Softlayer users Sinatra APAC SINATRA US-EAST
LEARN TO LEVERAGE REPLICATION
Sinatra APAC Cloudant APAC SINATRA US-EAST Cloudant US-East Cloudant SOFTLAYER
users
LEARN HOW TO TWEAK CONSISTENCY
Sinatra APAC Cloudant APAC SINATRA US-EAST Cloudant US-East Cloudant SOFTLAYER
users
LEARN TO OFFLOAD TO FRONT-END JS
Sinatra APAC Cloudant APAC SINATRA US-EAST Cloudant US-East Cloudant SOFTLAYER
users
LEARN TO CACHE SOME COUCHDB ROUTES
Sinatra APAC Cloudant APAC SINATRA US-EAST Cloudant US-East Cloudant SOFTLAYER
CDN 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
Go EXPERIMENT IMPLEMENT MEASURE IMPROVE HAVE FUN
Free plan BigCouch github.com /cloudant/bigcouch Open Source cloudant.com
github.com/timanglade cloudant.com
[email protected]
@timanglade ?