Module: ProconBypassMan::Procon::PerformanceMeasurement

Defined in:
lib/procon_bypass_man/procon/performance_measurement.rb,
lib/procon_bypass_man/procon/performance_measurement.rb

Defined Under Namespace

Classes: LastBypassAt, MeasurementCollection, MeasurementsSummarizer, PerformanceSpan, QueueOverProcess, SpanQueue, SpanTransferBuffer

Class Method Summary collapse

Class Method Details

.is_not_measure_with_random_or_if_fast(span:) ⇒ Object

全部送ると負荷になるので適当にまびく



55
56
57
58
59
# File 'lib/procon_bypass_man/procon/performance_measurement.rb', line 55

def self.is_not_measure_with_random_or_if_fast(span: )
  return false if span.time_taken > 0.1
  return true if rand(100) != 0 # 99/100は捨てる
  return false
end

.measure(&bypass_process_block) ⇒ Boolean

measureをして、measureの結果をためる



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/procon_bypass_man/procon/performance_measurement.rb', line 63

def self.measure(&bypass_process_block)
  unless ProconBypassMan.config.enable_procon_performance_measurement?
    bypass_process_block.call(PerformanceSpan.new)
    return
  end

  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.1.0")
    snapshot_gc_time = GC.stat(:time) / 1000.0
  end
  snapshot_gc_count = GC.count
  span = PerformanceSpan.new

  span.time_taken = Benchmark.realtime {
    span.succeed = bypass_process_block.call(span)
  }.floor(3)

  return if is_not_measure_with_random_or_if_fast(span: span)

  if span.succeed
    ProconBypassMan::Procon::PerformanceMeasurement::LastBypassAt.touch do |interval_from_previous_succeed|
      span.interval_from_previous_succeed = interval_from_previous_succeed.floor(3)
    end
  end

  (GC.count - snapshot_gc_count).tap do |increased_gc_count|
    span.gc_count = increased_gc_count
  end

  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.1.0")
    ((GC.stat(:time) / 1000.0) - snapshot_gc_time).tap do |increased_time|
      span.gc_time = increased_time
    end
  end

  # measureするたびにperform_asyncしているとjob queueが詰まるのでbufferingしている
  ProconBypassMan::Procon::PerformanceMeasurement::SpanTransferBuffer.instance.push_and_run_block_if_buffer_over(span) do |spans|
    ProconBypassMan::ProconPerformanceSpanTransferJob.perform_async(spans)
  end
  return span.succeed
end

.pop_measurement_collectionMeasurementCollection, NilClass

bypassしているプロセスから呼ばれる



106
107
108
# File 'lib/procon_bypass_man/procon/performance_measurement.rb', line 106

def self.pop_measurement_collection
  ProconBypassMan::Procon::PerformanceMeasurement::QueueOverProcess.pop
end

.summarize(spans:) ⇒ ProconBypassMan::Procon::PerformanceMeasurement::MeasurementsSummarizer::PerformanceMetric

jobから呼ばれる予定



113
114
115
# File 'lib/procon_bypass_man/procon/performance_measurement.rb', line 113

def self.summarize(spans: )
  ProconBypassMan::Procon::PerformanceMeasurement::MeasurementsSummarizer.new(spans: spans).summarize
end