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
gogaruco
September 27, 2011
310
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
Transcript
69 slides
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 ?
More Decks by gogaruco
See All by gogaruco
Wesley Beary at GoGaRuCo 2011
gogaruco
2
75
Ruby Javascript and the Mobile Web
gogaruco
1
95
KidsRuby: Think of the Children
gogaruco
1
180
Smalltalk on Rubinius
gogaruco
1
73
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
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
990
Exploring anti-patterns in Rails
aemeredith
4
570
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
350
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1k
Amusing Abliteration
ianozsvald
1
400
ラッコキーワード サービス紹介資料
rakko
5
5.9M
Game over? The fight for quality and originality in the time of robots
wayneb77
1
340
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
330
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470