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

Estratégias para tunar sua aplicação rails

Cirdes
November 29, 2014

Estratégias para tunar sua aplicação rails

Palestra na RuPy 2014

Cirdes

November 29, 2014
Tweet

More Decks by Cirdes

Other Decks in Programming

Transcript

  1. ANTES DA SOLUÇÃO, UM PASSO ATRÁS: 
 MONITORAR A APLICAÇÃO

    NewRelic Nazar.io HoneyBadger Logentries Inspectlet The Informant
  2. Cache é um componente que guarda informações de forma TRANSPARENTE


    
 para que futuras requisições
 sejam mais RÁPIDAS
  3. PAGE CACHE class WeblogController < ActionController::Base caches_page :show, :new def

    update expire_page action: 'show', id: params[:list][:id] end end
  4. FRAGMENT CACHING <% cache :recent_attendees, expires_in: 5.minutes do %> <%=

    render partial: 'recent', collection: Attendees.recent %> <% end %>
  5. FRAGMENT CACHING module AttendeesHelper def cache_key_for_attendees count = Attendee.count max_updated_at

    = Attendee.maximum(:updated_at).try(:utc).try(:to_s, :number) "attendees/all-#{count}-#{max_updated_at}" end end
  6. CACHE Digests <!-- app/views/events/show.html.erb --> <% cache ["v1", @event] do%>

    <h1>Team: <%= @event.title %></h1> <%= render @event.attendees %> <% end %> <!-- app/views/attendees/_attendee.html.erb --> <% cache ["v1", attendee] do %> <span><%= attendee.name %></span> <span><%= attendee.email %></span> <% end %>
  7. Russian Doll <% cache(cache_key_for_attendees) do %> All available attendees: <%

    Attendee.all.each do |a| %> <% cache(a) do %> <p><%= a.name %></p> <% end %> <% end %> <% end %>