Class: DeferredGarbageCollection
- Inherits:
-
Object
- Object
- DeferredGarbageCollection
- Defined in:
- lib/generators/voluntary/install/templates/spec/support/deferred_garbage_collector.rb,
lib/generators/voluntary/product_dummy/templates/spec/support/deferred_garbage_collector.rb
Overview
Constant Summary collapse
- DEFERRED_GC_THRESHOLD =
used to be 10.0
(ENV['DEFER_GC'] || 10.0).to_f
- @@last_gc_run =
Time.now
Class Method Summary collapse
Class Method Details
.memory_threshold ⇒ Object
13 14 15 16 17 |
# File 'lib/generators/voluntary/install/templates/spec/support/deferred_garbage_collector.rb', line 13 def self.memory_threshold @mem = %x(free 2>/dev/null).to_s.split(" ") return nil if @mem.empty? @mem[15].to_i / (@mem[7].to_i/100) end |
.reconsider ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/voluntary/install/templates/spec/support/deferred_garbage_collector.rb', line 19 def self.reconsider return if unsupported_enviroment if (percent_used = self.memory_threshold) running_out_of_memory = percent_used > 90 # just for info, as soon as we got some numbers remove it swap_percent_used = @mem[19].to_i / (@mem[18].to_i/100) rescue 0 puts "percent memory used #{percent_used} (#{@mem[8]} of #{@mem[7]})" puts "percent swap used #{swap_percent_used} (#{@mem[19]} of #{@mem[18]})" else running_out_of_memory = false end if( (DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD) || running_out_of_memory ) GC.enable GC.start GC.disable @@last_gc_run = Time.now end end |
.start ⇒ Object
8 9 10 11 |
# File 'lib/generators/voluntary/install/templates/spec/support/deferred_garbage_collector.rb', line 8 def self.start return if unsupported_enviroment GC.disable if DEFERRED_GC_THRESHOLD > 0 end |
.unsupported_enviroment ⇒ Object
41 42 43 |
# File 'lib/generators/voluntary/install/templates/spec/support/deferred_garbage_collector.rb', line 41 def self.unsupported_enviroment ENV['TRAVIS'] # TODO: enable for ruby 1.9.3 or more RAM end |