Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
require 'benchmark'
module Kernel
alias old_require require
def require(path)
#unless caller.find { |caller_line| caller_line.match /dependencies\.rb/ }
# return old_require(path)
#end
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
# WHAT: Provides a simple overview of memory allocation occuring during a
# require.
#
# For a longer explanation, see my post at:
#
# http://bitmonkey.net/post/308322913/tracking-initial-memory-usage-by-file-in-ruby
#
# ACK:
# modified from
# http://gist.github.com/264496
# http://gist.github.com/465293
# USAGE:
# 1) > ruby -rrequire_tracking -e "require 'active_support'"
# 2) put in config/preinitializer.rb
# WHAT: Provides a simple overview of memory allocation occuring
@deepak
deepak / require_tracking.rb
Created July 6, 2010 14:17
Gather memory usage per files required and the time taken - useful to reduce startup time
# ACK:
# modified from
# http://gist.github.com/264496 by github.com/eric
# http://gist.github.com/465293 by github.com/alexyoung
# USAGE:
# 1) > ruby -rrequire_tracking -e "require 'active_support'"
# 2) put in config/preinitializer.rb
# WHAT: Provides a simple overview of memory allocation occuring
# using memcache hosted on other-than localhost:11311 - needs better documentation
Rails::Initializer.run do |config|
config.cache_store = :mem_cache_store, '72.14.x.y:11311'
ActionController::Base.session = {
:key => '_foo_session',
:secret => 'secret',
:memcache_server => '72.14.x.y:11311'
}
@deepak
deepak / foo.rb
Created July 21, 2010 13:03
configure memcache on rails (hosted on other-than localhost:11311)
# using memcache hosted on other-than localhost:11311 - needs better documentation
Rails::Initializer.run do |config|
config.cache_store = :mem_cache_store, '72.14.x.y:11311'
ActionController::Base.session = {
:key => '_foo_session',
:secret => 'secret',
:memcache_server => '72.14.x.y:11311'
}
@deepak
deepak / mon_passenger.sh
Created July 28, 2010 06:32
collectd plugin to monitor passenger
#!/bin/bash
# collectd plugin to monitor passenger
# has better memory-requirement than a ruby script
# TODO: try writing it in c - if it makes a difference
HOSTNAME="production-host-01"
INTERVAL="${COLLECTD_INTERVAL:-10}"
PLUGIN_NAME="passenger_status"
while sleep "$INTERVAL"
@deepak
deepak / gem_make.out
Created July 30, 2010 06:11
stacktrace while installing memprof on a 32bit os (ubuntu 9.10) on a 64 bit cpu (interl core2 duo)
/home/deepak/.rvm/rubies/ree-1.8.7-2010.01/bin/ruby extconf.rb
checking for main() in -lyajl_ext... yes
checking for json/json_gen.h... yes
checking for gelf_getshdr() in -lelf_ext... yes
checking for main() in -ldwarf_ext... yes
checking for mach-o/dyld.h... no
creating Makefile
make
gcc -I. -I/home/deepak/.rvm/gems/ree-1.8.7-2010.01/gems/memprof-0.3.5/ext/dst/include -I/home/deepak/.rvm/gems/ree-1.8.7-2010.01/gems/memprof-0.3.5/ext/dst/include -I. -I/home/deepak/.rvm/rubies/ree-1.8.7-2010.01/lib/ruby/1.8/i686-linux -I. -DHAVE_JSON_JSON_GEN_H -DHAVE_ELF -DHAVE_DWARF -D_ARCH_i686_ -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -o tramp.o -c tramp.c
@deepak
deepak / json_generation.rb
Created July 30, 2010 08:48
benchmark json generation and parsing in rails/ruby
#!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
require 'nokogiri'
require 'yajl'
require 'active_support'
ActiveSupport::XmlMini.backend='Nokogiri'
require 'active_resource'
@deepak
deepak / console warnings
Created August 27, 2010 08:42
rails 2.3.5 console warnings
deepak@octo:~/src/work/entsupport$ ruby -dw ./script/console
Exception `LoadError' at /home/deepak/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems.rb:1113 - no such file to load -- rubygems/defaults/operating_system
Exception `LoadError' at /home/deepak/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems.rb:1122 - no such file to load -- rubygems/defaults/ruby
Exception `LoadError' at /home/deepak/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/config_file.rb:50 - no such file to load -- Win32API
Exception `LoadError' at /home/deepak/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31 - no such file to load -- ruby-debug
Exception `LoadError' at /home/deepak/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31 - no such file to load -- methodsig
Exception `LoadError' at /home/deepak/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:38 - no such file to load -- methodsig
Exception `