Sha256: eac383f76d1e921a69b35c146a8bcce2a642246f2d0d17f9a3706e10701f0de3

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

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

  # @param [Array<PerformanceSpan>] spans
  # bypassプロセスから呼ばれる. 実際に実行を行なっているのはmasterプロセス
  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

  # job workerから呼ばれる
  # @return [ProconBypassMan::Procon::PerformanceMeasurement::MeasurementCollection]
  def pop
    @measurement_collection_list.pop
  end

  private

  # 1分単位で次の値になる
  def generate_bucket_key
    Time.new.strftime("%Y-%m-%d %H:%M:00%:z")
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.12 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.11 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/procon/performance_measurement/span_queue.rb