Class: ScoutApm::SlowTransactionSet
- Inherits:
-
Object
- Object
- ScoutApm::SlowTransactionSet
- Includes:
- Enumerable
- Defined in:
- lib/scout_apm/slow_transaction_set.rb
Constant Summary collapse
- DEFAULT_TOTAL =
10
- DEFAULT_FAIR =
1
Instance Attribute Summary collapse
-
#fair ⇒ Object
readonly
Returns the value of attribute fair.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #<<(slow_transaction) ⇒ Object
- #attempt_append(slow_transaction) ⇒ Object
- #attempt_to_evict ⇒ Object
- #each ⇒ Object
- #empty_slot? ⇒ Boolean
-
#initialize(total = DEFAULT_TOTAL, fair = DEFAULT_FAIR) ⇒ SlowTransactionSet
constructor
A new instance of SlowTransactionSet.
Constructor Details
#initialize(total = DEFAULT_TOTAL, fair = DEFAULT_FAIR) ⇒ SlowTransactionSet
Returns a new instance of SlowTransactionSet.
23 24 25 26 27 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 23 def initialize(total=DEFAULT_TOTAL, fair=DEFAULT_FAIR) @total = total @fair = fair @slow_transactions = [] end |
Instance Attribute Details
#fair ⇒ Object (readonly)
Returns the value of attribute fair.
21 22 23 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 21 def fair @fair end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
21 22 23 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 21 def total @total end |
Instance Method Details
#<<(slow_transaction) ⇒ Object
33 34 35 36 37 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 33 def <<(slow_transaction) return if attempt_append(slow_transaction) attempt_to_evict attempt_append(slow_transaction) end |
#attempt_append(slow_transaction) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 43 def attempt_append(slow_transaction) if empty_slot? @slow_transactions.push(slow_transaction) true else false end end |
#attempt_to_evict ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 52 def attempt_to_evict return if @slow_transactions.length == 0 overrepresented = @slow_transactions. group_by { |st| st.metric_name }. to_a. sort_by { |(_, sts)| sts.length }. last if overrepresented[1].length > fair fastest = overrepresented[1].sort_by { |st| st.total_call_time }.first @slow_transactions.delete(fastest) end end |
#each ⇒ Object
29 30 31 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 29 def each @slow_transactions.each { |s| yield s } end |
#empty_slot? ⇒ Boolean
39 40 41 |
# File 'lib/scout_apm/slow_transaction_set.rb', line 39 def empty_slot? @slow_transactions.length < total end |