Profiling Ruby with ruby-prof

require 'ruby-prof' # you don't need this if you have ruby-prof in your Gemfile

You can set one of the things you want to measure by using (default is PROCESS_TIME most useful ones are PROCESS_TIME, MEMORY, CPU_TIME):
RubyProf.measure_mode = RubyProf::PROCESS_TIME
RubyProf.measure_mode = RubyProf::WALL_TIME
RubyProf.measure_mode = RubyProf::CPU_TIME
RubyProf.measure_mode = RubyProf::ALLOCATIONS
RubyProf.measure_mode = RubyProf::MEMORY
RubyProf.measure_mode = RubyProf::GC_RUNS
RubyProf.measure_mode = ...

How to run long scripts on production/staging server

In a nutshell, use screen

Why?
Sometimes we are concerned that if our connection gets closed, the process we are running will close too.

The processes or login sessions you establish through screen don't go away. You can resume your screen sessions.

How?

  1. run screen command
    screen
    or you can give that screen a name (will help afterwards)
    screen -S some_name

  2. run your time consuming command
    script/runner path_to_some_long_script.rb

  3. detatch from your screen with the following commands

  • `Crt...

Caching: don't use content_for, it won't work

Do not use content_for inside a cached view fragment. It won't work because Memcache will just output whatever is in the cache, and not execute such commands.