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

gems, executáveis e configurações

Lucas Mazza
September 18, 2015

gems, executáveis e configurações

Lucas Mazza

September 18, 2015
Tweet

More Decks by Lucas Mazza

Other Decks in Technology

Transcript

  1. GET /orders SELECT * FROM orders WHERE user_id = ?

    GET /oauth/tokens redis GET cache/orders/12893128739
  2. GET /orders SELECT * FROM orders WHERE user_id = ?

    GET /oauth/tokens redis SADD queues:default ‘{job: “…”}’ redis GET cache/orders/12893128739
  3. GET /orders SELECT * FROM orders WHERE user_id = ?

    GET /oauth/tokens redis SADD queues:default ‘{job: “…”}’ ☕☕☕ redis GET cache/orders/12893128739
  4. GET /orders orders/index.html.erb SELECT * FROM orders WHERE user_id =

    ? GET /oauth/tokens redis SADD queues:default ‘{job: “…”}’ ☕☕☕ redis GET cache/orders/12893128739
  5. “Reality doesn’t exist until we measure it*” *at least on

    a very small scale http:/ /www.sciencealert.com/reality-doesn-t-exist-until-we-measure-it-quantum-experiment-confirms
  6. • Quais recursos externos a aplicação depende? • Quanto tempo/memória

    é gasto em cada operação? • O que deu certo e o que deu errado?
  7. Article.first # Article Load (0.4ms) SELECT * from "articles.*" ...

    Article.where(published: true).count # SELECT COUNT(*) from "articles.*" ...
  8. module Faraday class LogSubscriber < ActiveSupport::LogSubscriber def request(event) # ...

    end attach_to :faraday end end ActiveSupport::Notifications.instrument 'faraday.request' do # ... end
  9. module attach_to end ActiveSupport end An Instrumented Library in ~

    30 minutes http:/ /www.railstips.org/blog/archives/2013/01/23/an-instrumented-library-in-30-lines/
  10. $ derailed bundle:mem TOP: 53.043 MiB rails/all: 17.7539 MiB active_record/railtie:

    8.7227 MiB active_record: 7.5273 MiB arel: 3.2109 MiB arel/nodes: 1.2539 MiB arel/visitors: 1.1172 MiB arel/visitors/to_sql: 0.4648 MiB active_record/type: 0.8867 MiB
  11. derailed bundle:objects Measuring objects created by gems in groups [:default,

    "production"] Total allocated: 14388737 bytes (94532 objects) Total retained: 5009330 bytes (14661 objects) allocated memory by gem ----------------------------------- 4572996 activesupport-4.2.4 2832576 actionpack-4.2.4 1370497 therubyracer-0.12.2 957367 commonjs-0.2.7 572490 2.2.2/lib 463779 bundler-1.10.6
  12. # Gemfile gem 'rails', '4.2.4' # Gemfile gem 'actionmailer', '4.2.4'

    gem 'actionpack', '4.2.4' gem 'actionview', '4.2.4' gem 'activejob', '4.2.4' gem 'activemodel', '4.2.4' gem 'activerecord', '4.2.4' gem 'activesupport', '4.2.4' gem 'railties', '4.2.1' gem 'sprockets-rails'
  13. # config/application.rb require 'rails/all' # config/application.rb require 'active_record/railtie' require 'action_controller/railtie'

    require 'action_view/railtie' require 'action_mailer/railtie' require 'active_job/railtie' require 'rails/test_unit/railtie' require 'sprockets/railtie'
  14. # config/application.rb require 'rails/all' # config/application.rb require 'active_record/railtie' require 'action_controller/railtie'

    require 'action_view/railtie' require 'action_mailer/railtie' require 'active_job/railtie' require 'rails/test_unit/railtie' require 'sprockets/railtie'
  15. A. Sem CSS/JavaScript? B. Sem banco relacional? C. Sem background

    jobs? D. Sem envio de emails? E. Todos as anteriores.
  16. • Reduz o tempo de boot e instalação • Pode

    reduzir o uso de memória • Simplifica a árvore de dependências
  17. • Todas as configurações em um arquivo só • Configuração

    auto documentável • Portabilidade entre ambientes
  18. You have already activated activesupport 4.2.4, but your Gemfile requires

    activesupport 4.2.3. Prepending `bundle exec` to your command may solve this. (╯°□°)╯︵ ┻━┻
  19. • Como eu instalo “X” ? • Diferença de versões

    • Configurações e dependências externas
  20. • Como eu instalo “X” ? • Diferença de versões

    • Configurações e dependências externas • bin/setup && bin/rake = ,
  21. ✓ versão do ruby ✓ pg, redis, memcache ✓ arquivos

    de configuração ✓ bundle/bower/npm install
  22. ✓ versão do ruby ✓ pg, redis, memcache ✓ arquivos

    de configuração ✓ bundle/bower/npm install ✓ APIs, sandboxes, etc
  23. #!/usr/bin/env ruby require 'pathname' APP_ROOT = Pathname.new File.expand_path('..', __dir__) Dir.chdir

    APP_ROOT do puts '== Installing dependencies ==' system 'gem install bundler --conservative' system('bundle check') or system('bundle install') puts "\n== Preparing database ==" system 'ruby bin/rake db:setup' system 'RAILS_ENV=test ruby bin/rake db:create' puts "\n== Removing old logs and tempfiles ==" system 'ruby bin/rake log:clear tmp:clear' end
  24. #!/usr/bin/env bash echo "Setting up your environment..." # ... check_ruby

    "$(cat .ruby-version)" test_dependency "psql" "PostgreSQL" "brew install postgresql" test_dependency "redis-cli" "Redis" "brew install redis" test_dependency "docker" "docker" "brew cask install dockertoolbox" install_bundler # ... download_phantomjs_2 bundle_install copy_dotenv torba_install setup_db echo "Done!"
  25. #!/usr/bin/env bash # USAGE: deploy [ENVIRONMENT] # # This program

    check for all deployment prerequisites before running the # Capistrano deployment task. # We currently check for the following dependencies: # # * Current ruby version. # * The gem dependencies listed in the Gemfile. bundle check &> /dev/null || bundle install --quiet exec bin/cap ${1:-"production"} deploy
  26. # bin/pull-db #!/usr/bin/env bash set -e timestamp=$(date +%s) ssh [email protected]

    "pg_dump -U DB_USER -W DB_NAME -Fc > ~/dump-$timestamp.dump" scp [email protected]:"dump-$timestamp.dump" "/tmp/dump-$timestamp.dump" pg_restore --verbose --clean --no-acl --no-owner -h localhost -U \ $USER -d DB_DEV_NAME "/tmp/dump-$timestamp.dump"