Class: Ecoportal::API::Common::Client::Throughput
- Inherits:
-
Object
- Object
- Ecoportal::API::Common::Client::Throughput
- Defined in:
- lib/ecoportal/api/common/client/throughput.rb,
lib/ecoportal/api/common/client/throughput/stats.rb
Defined Under Namespace
Classes: Stats
Constant Summary collapse
- MIN_THROUGHPUT =
records per second
0.2
- MAX_THROUGHPUT =
12
Instance Attribute Summary collapse
-
#default_approach ⇒ Object
readonly
Returns the value of attribute default_approach.
Instance Method Summary collapse
- #around_min_throughput?(margin) ⇒ Boolean
- #eta_for(count, approach: default_approach, ratio: self.ratio(approach)) ⇒ Object
-
#initialize(approach = :conservative) ⇒ Throughput
constructor
A new instance of Throughput.
-
#push(value) ⇒ Object
(also: #<<)
Keeps track of the current processing speed.
- #ratio(approach = default_approach) ⇒ Object
- #record!(secs = nil, count: nil) ⇒ Object
Constructor Details
#initialize(approach = :conservative) ⇒ Throughput
Returns a new instance of Throughput.
13 14 15 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 13 def initialize(approach = :conservative) @default_approach = approach || :conservative end |
Instance Attribute Details
#default_approach ⇒ Object (readonly)
Returns the value of attribute default_approach.
11 12 13 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 11 def default_approach @default_approach end |
Instance Method Details
#around_min_throughput?(margin) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 55 def around_min_throughput?(margin) rate = ratio return true if rate == min_throughput right_under = min_throughput * (1 - margin) return false if rate < right_under right_above = min_throughput * (1 + margin) return false if rate > right_above true end |
#eta_for(count, approach: default_approach, ratio: self.ratio(approach)) ⇒ Object
17 18 19 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 17 def eta_for(count, approach: default_approach, ratio: self.ratio(approach)) to_seconds(count, ratio: ratio) end |
#push(value) ⇒ Object Also known as: <<
Note:
it needs to be called in specific spots
Keeps track of the current processing speed
50 51 52 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 50 def push(value) stats.record!(value) end |
#ratio(approach = default_approach) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 21 def ratio(approach = default_approach) case approach when :min min_throughput when :last @last_throughput || stats.average when :average stats.average when :optimistic [stats.max, max_throughput].min else # :conservative [stats.min, min_throughput].max end.then do |relation| next relation if relation < max_throughput max_throughput end end |
#record!(secs = nil, count: nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/ecoportal/api/common/client/throughput.rb', line 40 def record!(secs = nil, count: nil) return ratio if secs.to_f.zero? || count.to_i.zero? (count / secs.to_f).round(3).tap do |last| stats << @last_throughput = last end end |