Commit e1a8e5a5 authored by Stan Hu's avatar Stan Hu

Remove allocation tracking code from InfluxDB sampler for performance

On GitLab.com, InfluxSampler#sample_objects appears to take 1.2 s or so to
iterate through 1059 objects. This had led to delays of a couple hundred
milliseconds in processing in the main thread. Remove this code since it's not
really being used.

Closes gitlab-com/infrastructure#3250
parent 806a68a8
---
title: Remove allocation tracking code from InfluxDB sampler for performance
merge_request:
author:
type: performance
...@@ -27,7 +27,6 @@ module Gitlab ...@@ -27,7 +27,6 @@ module Gitlab
def sample def sample
sample_memory_usage sample_memory_usage
sample_file_descriptors sample_file_descriptors
sample_objects
sample_gc sample_gc
flush flush
...@@ -48,29 +47,6 @@ module Gitlab ...@@ -48,29 +47,6 @@ module Gitlab
add_metric('file_descriptors', value: System.file_descriptor_count) add_metric('file_descriptors', value: System.file_descriptor_count)
end end
if Metrics.mri?
def sample_objects
sample = Allocations.to_hash
counts = sample.each_with_object({}) do |(klass, count), hash|
name = klass.name
next unless name
hash[name] = count
end
# Symbols aren't allocated so we'll need to add those manually.
counts['Symbol'] = Symbol.all_symbols.length
counts.each do |name, count|
add_metric('object_counts', { count: count }, type: name)
end
end
else
def sample_objects
end
end
def sample_gc def sample_gc
time = GC::Profiler.total_time * 1000.0 time = GC::Profiler.total_time * 1000.0
stats = GC.stat.merge(total_time: time) stats = GC.stat.merge(total_time: time)
......
...@@ -21,7 +21,6 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do ...@@ -21,7 +21,6 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do
it 'samples various statistics' do it 'samples various statistics' do
expect(sampler).to receive(:sample_memory_usage) expect(sampler).to receive(:sample_memory_usage)
expect(sampler).to receive(:sample_file_descriptors) expect(sampler).to receive(:sample_file_descriptors)
expect(sampler).to receive(:sample_objects)
expect(sampler).to receive(:sample_gc) expect(sampler).to receive(:sample_gc)
expect(sampler).to receive(:flush) expect(sampler).to receive(:flush)
...@@ -72,28 +71,6 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do ...@@ -72,28 +71,6 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do
end end
end end
if Gitlab::Metrics.mri?
describe '#sample_objects' do
it 'adds a metric containing the amount of allocated objects' do
expect(sampler).to receive(:add_metric)
.with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash))
.at_least(:once)
.and_call_original
sampler.sample_objects
end
it 'ignores classes without a name' do
expect(Allocations).to receive(:to_hash).and_return({ Class.new => 4 })
expect(sampler).not_to receive(:add_metric)
.with('object_counts', an_instance_of(Hash), type: nil)
sampler.sample_objects
end
end
end
describe '#sample_gc' do describe '#sample_gc' do
it 'adds a metric containing garbage collection statistics' do it 'adds a metric containing garbage collection statistics' do
expect(GC::Profiler).to receive(:total_time).and_return(0.24) expect(GC::Profiler).to receive(:total_time).and_return(0.24)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment