lib/scout_rails/store.rb in scout_rails-1.1.5.pre3 vs lib/scout_rails/store.rb in scout_rails-1.1.5.pre4
- old
+ new
@@ -2,10 +2,13 @@
# of instrumented methods that are being called. It's accessed via +ScoutRails::Agent.instance.store+.
class ScoutRails::Store
# Limits the size of the metric hash to prevent a metric explosion.
MAX_SIZE = 1000
+
+ # Limit the number of samples that we store metrics with to prevent writing too much data to the layaway file if there are are many processes and many slow samples.
+ MAX_SAMPLES_TO_STORE_METRICS = 10
attr_accessor :metric_hash
attr_accessor :transaction_hash
attr_accessor :stack
attr_accessor :sample
@@ -191,9 +194,19 @@
end
end
metric_hash
end
+ # Merges samples together, removing transaction sample metrics from samples if the > MAX_SAMPLES_TO_STORE_METRICS
def merge_samples(old_samples)
+ # need transaction lock here?
self.samples += old_samples
+ if trim_samples = self.samples[MAX_SAMPLES_TO_STORE_METRICS..-1]
+ ScoutRails::Agent.instance.logger.debug "Trimming metrics from #{trim_samples.size} samples."
+ i = MAX_SAMPLES_TO_STORE_METRICS
+ trim_samples.each do |sample|
+ self.samples[i] = sample.clear_metrics!
+ end
+ end
+ self.samples
end
end # class Store
\ No newline at end of file