Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CouchDB & Ruby - You're doing it wrong

gogaruco
September 27, 2011
290

CouchDB & Ruby - You're doing it wrong

by Tim Anglade

gogaruco

September 27, 2011
Tweet

Transcript

  1. Ruby: 10% OF our USERS 65% OF the I/O That’s

    called having a vested interest, my Friends
  2. 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 …" }
  3. 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 …" }
  4. 0 200 400 600 800 1k 10k 50k 100k MEDIAN

    TIME TO SAVE A DOC Time spent (ms) Document Size
  5. 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 …" }
  6. 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
  7. 0 200 400 600 800 1k 10k 50k 100k Before

    Time spent (ms) Document Size Encoding HTTP Decoding
  8. 0 200 400 600 800 1k 10k 50k 100k Before

    Time spent (ms) Document Size Encoding HTTP Decoding
  9. 0 200 400 600 800 1k 10k 50k 100k Time

    spent (ms) Document Size Encoding HTTP Decoding AFTER
  10. AFTER 0 8 15 23 30 1k 10k 50k 100k

    Time spent (ms) Document Size Encoding HTTP Decoding
  11. 0 8 15 23 30 1k 10k 50k 100k With

    MessagePACK Encoding HTTP Decoding JSON 3ms 6MS 9MS 3ms
  12. GROUP INFO ONE HTTP CALL PER RUBY METHOD Write views

    as necessary IF you can’t ➡ Wrong DB?
  13. { "_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!" } } }
  14. LEARN HOW TO USE BULK_DOCS A no-brainer if you do

    multiple updates inSIDE one ruby method
  15. 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