Class: SolidCache::Entry::Size::MovingAverageEstimate
- Inherits:
-
Object
- Object
- SolidCache::Entry::Size::MovingAverageEstimate
- Defined in:
- app/models/solid_cache/entry/size/moving_average_estimate.rb
Overview
Moving average cache size estimation
To reduce variability in the cache size estimate, we’ll use a moving average of the previous 20 estimates. The estimates are stored directly in the cache, under the “__solid_cache_entry_size_moving_average_estimates” key.
We’ll remove the largest and smallest estimates, and then average remaining ones.
Constant Summary collapse
- ESTIMATES_KEY =
"__solid_cache_entry_size_moving_average_estimates"
- MAX_RETAINED_ESTIMATES =
50
- TARGET_SAMPLED_FRACTION =
0.0005
Instance Attribute Summary collapse
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(samples:) ⇒ MovingAverageEstimate
constructor
A new instance of MovingAverageEstimate.
Constructor Details
#initialize(samples:) ⇒ MovingAverageEstimate
Returns a new instance of MovingAverageEstimate.
20 21 22 23 24 25 26 |
# File 'app/models/solid_cache/entry/size/moving_average_estimate.rb', line 20 def initialize(samples:) @samples = samples @estimate = Estimate.new(samples: samples) values = latest_values @size = (values.sum / values.size.to_f).round write_values(values) end |
Instance Attribute Details
#samples ⇒ Object (readonly)
Returns the value of attribute samples.
17 18 19 |
# File 'app/models/solid_cache/entry/size/moving_average_estimate.rb', line 17 def samples @samples end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
17 18 19 |
# File 'app/models/solid_cache/entry/size/moving_average_estimate.rb', line 17 def size @size end |