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

Facepalm to Foolproof - RubyConf India 2016

Facepalm to Foolproof - RubyConf India 2016

Video: https://www.youtube.com/watch?v=V6yLT6vDB5k

If you're new to Rails development, or just want some tips on deploying and running in production, this is the talk for you. Relying on real-world experience as part of the Heroku support team, we'll talk through common issues (and a few funny ones) we see when people take their "but it works in development!" app to a production environment.

Jon McCartie

March 20, 2016
Tweet

More Decks by Jon McCartie

Other Decks in Programming

Transcript

  1. $ ab -c 100 -n 500 http://airlessbnb.com/ Requests per second:

    41.53 [#/sec] (mean) Time per request: 2407.916 [ms] (mean) Time per request: 24.079 [ms]
  2. # Gemfile gem ‘puma' # Procfile web: bundle exec puma

    -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
  3. $ ab -c 100 -n 500 http://airlessbnb.com/ Requests per second:

    41.53 [#/sec] (mean) Time per request: 2407.916 [ms] (mean) Time per request: 24.079 [ms]
  4. $ ab -c 100 -n 500 http://airlessbnb.com/ Requests per second:

    82.94 [#/sec] (mean) Time per request: 1205.721 [ms] (mean) Time per request: 12.057 [ms]
  5. ?

  6. Memory Enemies 1. Memory leaks - https:/ /github.com/schneems/derailed_benchmarks - https:/

    /blog.codeship.com/debugging-a-memory-leak-on-heroku/ 2. Too many web processes - how much memory does your Rails app consume in one web worker? - how much memory do you have?
  7. $ free -m total used free shared buffers cached Mem:

    8014 7528 486 141 291 4789 -/+ buffers/cache: 2446 5567 Swap: 511 7 504 Watch Your Memory Usage
  8. $ free -m total used free shared buffers cached Mem:

    8014 7528 486 141 291 4789 -/+ buffers/cache: 2446 5567 Swap: 511 7 504 Watch Your Memory Usage
  9. $ free -m total used free shared buffers cached Mem:

    8014 7528 486 141 291 4789 -/+ buffers/cache: 2446 5567 Swap: 511 7 504 Watch Your Memory Usage
  10. $ free -m total used free shared buffers cached Mem:

    8014 7528 486 141 291 4789 -/+ buffers/cache: 2446 5567 Swap: 511 7 504 Watch Your Memory Usage
  11. $ mina deploy -----> Creating the build path -----> Cloning

    the Git repository -----> Installing gem dependencies using Bundler -----> Moving to releases/4 -----> Symlinking to current -----> Launching -----> Done. Deployed v4
  12. $ heroku create sushi Creating sushi... done http://sushi.herokuapp.com/ | [email protected]:sushi.git

    $ git push heroku master ----> Heroku receiving push ----> Rails app detected ----> Compiled slug size is 8.0MB http://sushi.herokuapp.com deployed to heroku
  13. =>

  14. # Gemfile
 gem "dotenv-rails"
 # .env (.gitignore!)
 SECRET_KEY=foo
 # on

    heroku
 heroku config:add SECRET_KEY=foo
 # in your app
 ENV["foo"]
  15. # Small App (5,761 records) User Load (2.3ms) SELECT "users".*

    FROM "users" WHERE "users"."username" = "jmccartie" # Large App (231,138 records) User Load (51.7ms) SELECT "users".* FROM "users" WHERE "users"."username" = "jmccartie"
  16. # Small App (5,761 records) User Load (2.3ms) SELECT "users".*

    FROM "users" WHERE "users"."username" = "jmccartie" # Large App (231,138 records) User Load (51.7ms) SELECT "users".* FROM "users" WHERE "users"."username" = "jmccartie"
  17. # Small App (5,761 records) User Load (2.3ms) SELECT "users".*

    FROM "users" WHERE "users"."username" = "jmccartie" # Large App (231,138 records) User Load (51.7ms) SELECT "users".* FROM "users" WHERE "users"."username" = "jmccartie"
  18. # Before User Load (51.7ms) SELECT "users".* FROM "users" WHERE

    "users"."username" = "jmccartie" # After User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."username" = "jmccartie" Database Indexes
  19. # Before User Load (51.7ms) SELECT "users".* FROM "users" WHERE

    "users"."username" = "jmccartie" # After User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."username" = "jmccartie" Database Indexes
  20. # photos_controller.rb @photos = Photo.order(:name) # index.slim - @photos do

    |photo| = image_tag photo.url p= photo.user.username
  21. Photo Load (0.2ms) SELECT "photos".* FROM "photos" ORDER BY name

    User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 5 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 4 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 6 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 7 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 8 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 9
  22. N+1

  23. # Old Photo Load (0.2ms) SELECT "photos".* FROM "photos" ORDER

    BY name User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 5 User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 4 User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 N+1 Queries
  24. # New Photo Load (0.2ms) SELECT "photos".* FROM "photos" LIMIT

    0, 30 User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IN (3, 1, 5, 4, 2) N+1 Queries
  25. # Gemfile gem 'bullet', group: :development # Logs 2016-02-25 20:40:17[INFO]

    N+1 Query: PATH_INFO: /photos; model: Photo => associations: [users]· Add to your finder: :include => [:users] N+1 Queries