Class: UnicornWrangler::OutOfBandGC
- Inherits:
-
Object
- Object
- UnicornWrangler::OutOfBandGC
- Defined in:
- lib/unicorn_wrangler.rb
Overview
Do not run GC inside of requests, but only after a certain time spent in requests
Alternative: github.com/tmm1/gctools which is more sophisticated and will result in less time spent GCing and less overall memory needed
Instance Method Summary collapse
- #call(_requests, request_time) ⇒ Object
-
#initialize(logger, stats, max_request_time) ⇒ OutOfBandGC
constructor
A new instance of OutOfBandGC.
Constructor Details
#initialize(logger, stats, max_request_time) ⇒ OutOfBandGC
Returns a new instance of OutOfBandGC.
183 184 185 186 187 188 189 |
# File 'lib/unicorn_wrangler.rb', line 183 def initialize(logger, stats, max_request_time) @logger = logger @stats = stats @max_request_time = max_request_time @logger.info "Garbage collecting after #{@max_request_time}s of request processing time" @gc_ran_at = 0 end |
Instance Method Details
#call(_requests, request_time) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/unicorn_wrangler.rb', line 191 def call(_requests, request_time) time_since_last_gc = request_time - @gc_ran_at return unless time_since_last_gc >= @max_request_time @gc_ran_at = request_time time = Benchmark.realtime do GC.enable GC.start GC.disable end time = (time * 1000).round # s -> ms if @stats @stats.increment("#{STATS_NAMESPACE}.oobgc.runs") @stats.timing("#{STATS_NAMESPACE}.oobgc.time", time) end @logger.debug "Garbage collecting: took #{time}ms" true end |