CouchDB & Ruby: You’re Doing it Wrong

12,825
-1

Published on

As giv

Published in: Technology, Travel

CouchDB & Ruby: You’re Doing it Wrong

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

    Clipping is a handy way to collect important slides you want to go back to later.

×