Class: ProconBypassMan::Procon::PerformanceMeasurement::SpanQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/performance_measurement/span_queue.rb

Instance Method Summary collapse

Constructor Details

#initializeSpanQueue

Returns a new instance of SpanQueue.



2
3
4
5
# File 'lib/procon_bypass_man/procon/performance_measurement/span_queue.rb', line 2

def initialize
  @current_table = {} # 1つのスレッドからしか触らないのでlockはいらない
  @measurement_collection_list = [] # main threadとjob worker threadから触るのでlockが必要
end

Instance Method Details

#popProconBypassMan::Procon::PerformanceMeasurement::MeasurementCollection

job workerから呼ばれる



32
33
34
# File 'lib/procon_bypass_man/procon/performance_measurement/span_queue.rb', line 32

def pop
  @measurement_collection_list.pop
end

#push(new_spans) ⇒ Object

bypassプロセスから呼ばれる. 実際に実行を行なっているのはmasterプロセス

Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/procon_bypass_man/procon/performance_measurement/span_queue.rb', line 9

def push(new_spans)
  current_key = generate_bucket_key

  if @current_table[current_key].nil?
    if not @current_table.empty?
      timestamp_key = @current_table.keys.first
      spans = @current_table.values.first
      # 本当ならmutexでlockする必要があるけど、正確性はいらないのでパフォーマンスを上げるためにlockしない
      @measurement_collection_list.push(
        ProconBypassMan::Procon::PerformanceMeasurement::MeasurementCollection.new(timestamp_key: timestamp_key, spans: spans)
      )
    end

    @current_table = {}
    @current_table[current_key] = []
    @current_table[current_key].concat(new_spans)
  else
    @current_table[current_key].concat(new_spans)
  end
end