Skip to content

Instantly share code, notes, and snippets.

@eric
eric / gist:242966
Created November 25, 2009 19:41
Based on a great idea from @jnewland
diff --git a/lib/god/process.rb b/lib/god/process.rb
index 338da5e..6cbc867 100644
--- a/lib/god/process.rb
+++ b/lib/god/process.rb
@@ -6,7 +6,7 @@ module God
:unix_socket, :chroot, :env, :dir
def initialize
- self.log = '/dev/null'
+ self.log = nil
(gdb) ruby objects classes
1 YAML::Syck::Resolver
1 YAML::Syck::Resolver
1 SystemStackError
1 Object
1 Object
1 NoMemoryError
1 fatal
1 Object
1 Gem::ConfigFile
diff --git a/lib/god/logger.rb b/lib/god/logger.rb
index 7c45679..b08d0f8 100644
--- a/lib/god/logger.rb
+++ b/lib/god/logger.rb
@@ -58,21 +58,27 @@ module God
def log(watch, level, text)
# initialize watch log if necessary
self.logs[watch.name] ||= Timeline.new(God::LOG_BUFFER_SIZE_DEFAULT) if watch
-
+
[9 : 0] eric@kiccoro:/Users/eric/src > ruby thread_sender.rb
testing 1: #<Thread:0x101419bf8 run>
testing 2: #<Thread:0x101419bf8 run>
#<Thread:0x100170358 run>
require 'open3'
module ShellJob
@queue = :default
def self.perform(*args)
puts "$ #{args.join(' ')}"
Open3.popen3(*args) do |stdin, stdout, stderr|
puts stdout.read.inspect
end
$null = File.open('/dev/null', 'w')
threads = []
max_threads = 5000
loop do
threads << Thread.new do
str = 'x' * 500
$null.write(str)
end
CRYPT [99 : 0] eric@kibo:/home/eric/god-memory-testing > pprof --text /usr/bin/ruby --base=god-3.hprof.0001.heap god-3.hprof.0002.heap
Total: 1.4 MB
1.0 72.0% 72.0% 1.0 72.0% ruby_xmalloc
0.4 26.5% 98.5% 0.4 27.6% ruby_xrealloc
0.0 1.6% 100.1% 0.0 1.6% rb_thread_save_context
0.0 0.4% 100.4% 0.0 0.4% ruby_re_copy_registers
0.0 0.0% 100.4% 0.0 0.1% sym_inspect
0.0 0.0% 100.4% 0.1 3.7% rb_obj_alloc
0.0 0.0% 100.4% 0.0 0.0% rb_define_class_id
0.0 0.0% 100.4% 0.9 62.9% all_iter_i
CRYPT [93 : 0] eric@kibo:/home/eric/god-memory-testing > pprof --text /usr/bin/ruby god-2.hprof.0004.heap
Total: 7.9 MB
5.3 66.7% 66.7% 5.3 66.7% add_heap
2.0 24.9% 91.5% 2.0 24.9% ruby_xmalloc
0.3 3.6% 95.1% 0.3 3.6% ruby_re_compile_pattern
0.3 3.2% 98.3% 0.3 3.3% ruby_xrealloc
0.0 0.6% 98.8% 0.0 0.6% rb_thread_save_context
0.0 0.5% 99.4% 0.0 0.5% CRYPTO_malloc
0.0 0.3% 99.7% 0.0 0.3% _dl_new_object
0.0 0.1% 99.8% 0.0 0.1% CRYPTO_realloc
Displaying top 20 most common line/class pairs
109371 total objects
109371 filled heap slots
114325 free heap slots
3572 /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:186:String
3053 __null__:__null__:__node__
1265 /usr/lib/ruby/1.8/x86_64-linux/openssl.so:__null__:__node__
1248 /usr/lib/ruby/gems/1.8/specifications/passenger-2.2.5.gemspec:15:String
570 (eval):4:__node__
448 /usr/lib/ruby/1.8/fileutils.rb:1578:__node__
WATCHERS = 10
# Make sure pid directories exists
FileUtils.mkdir_p '/tmp/profiler-pids'
God.pid_file_directory = '/tmp/profiler-pids'
God::Logger.syslog = false
WATCHERS.times do |i|
God.watch do |w|