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
Navigating Weather and Climate Data
rabernat
0
540
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
Odyssey Design
rkendrick25
PRO
2
820
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Music & Morning Musume
bryan
48
7.4k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
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 ?