Welcome to mirror list, hosted at ThFree Co, Russian Federation.

memory_spec.rb « metrics « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fd8ca3b37c634eb56047f6ad9160b18ca90bf217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Metrics::Memory do
  describe '.gc_heap_fragmentation' do
    subject(:call) do
      described_class.gc_heap_fragmentation(
        heap_live_slots: gc_stat_heap_live_slots,
        heap_eden_pages: gc_stat_heap_eden_pages
      )
    end

    context 'when the Ruby heap is perfectly utilized' do
      # All objects are located in a single heap page.
      let(:gc_stat_heap_live_slots) { described_class::HEAP_SLOTS_PER_PAGE }
      let(:gc_stat_heap_eden_pages) { 1 }

      it { is_expected.to eq(0) }
    end

    context 'when the Ruby heap is greatly fragmented' do
      # There is one object per heap page.
      let(:gc_stat_heap_live_slots) { described_class::HEAP_SLOTS_PER_PAGE }
      let(:gc_stat_heap_eden_pages) { described_class::HEAP_SLOTS_PER_PAGE }

      # The heap can never be "perfectly fragmented" because that would require
      # zero objects per page.
      it { is_expected.to be > 0.99 }
    end

    context 'when the Ruby heap is semi-fragmented' do
      # All objects are spread over two pages i.e. each page is 50% utilized.
      let(:gc_stat_heap_live_slots) { described_class::HEAP_SLOTS_PER_PAGE }
      let(:gc_stat_heap_eden_pages) { 2 }

      it { is_expected.to eq(0.5) }
    end
  end
end