Module: Legion::Extensions::Synapse::Helpers::Homeostasis
- Defined in:
- lib/legion/extensions/synapse/helpers/homeostasis.rb
Constant Summary collapse
- SPIKE_MULTIPLIER =
3.0- SPIKE_DURATION_SECONDS =
60- DROUGHT_MULTIPLIER =
10.0
Class Method Summary collapse
- .drought?(current_throughput, baseline_throughput, silent_seconds: 0) ⇒ Boolean
- .should_dampen?(current_throughput, baseline_throughput, duration_seconds: 0) ⇒ Boolean
- .should_flag_for_review?(current_throughput, baseline_throughput, silent_seconds: 0) ⇒ Boolean
- .spike?(current_throughput, baseline_throughput, duration_seconds: 0) ⇒ Boolean
- .update_baseline(current_baseline, new_sample, alpha: 0.1) ⇒ Object
Class Method Details
.drought?(current_throughput, baseline_throughput, silent_seconds: 0) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/legion/extensions/synapse/helpers/homeostasis.rb', line 20 def drought?(current_throughput, baseline_throughput, silent_seconds: 0) return false if baseline_throughput <= 0 avg_interval = 60.0 / baseline_throughput current_throughput.zero? && silent_seconds >= (avg_interval * DROUGHT_MULTIPLIER) end |
.should_dampen?(current_throughput, baseline_throughput, duration_seconds: 0) ⇒ Boolean
31 32 33 |
# File 'lib/legion/extensions/synapse/helpers/homeostasis.rb', line 31 def should_dampen?(current_throughput, baseline_throughput, duration_seconds: 0) spike?(current_throughput, baseline_throughput, duration_seconds: duration_seconds) end |
.should_flag_for_review?(current_throughput, baseline_throughput, silent_seconds: 0) ⇒ Boolean
35 36 37 |
# File 'lib/legion/extensions/synapse/helpers/homeostasis.rb', line 35 def should_flag_for_review?(current_throughput, baseline_throughput, silent_seconds: 0) drought?(current_throughput, baseline_throughput, silent_seconds: silent_seconds) end |
.spike?(current_throughput, baseline_throughput, duration_seconds: 0) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/legion/extensions/synapse/helpers/homeostasis.rb', line 13 def spike?(current_throughput, baseline_throughput, duration_seconds: 0) return false if baseline_throughput <= 0 current_throughput > (baseline_throughput * SPIKE_MULTIPLIER) && duration_seconds >= SPIKE_DURATION_SECONDS end |
.update_baseline(current_baseline, new_sample, alpha: 0.1) ⇒ Object
27 28 29 |
# File 'lib/legion/extensions/synapse/helpers/homeostasis.rb', line 27 def update_baseline(current_baseline, new_sample, alpha: 0.1) ((1 - alpha) * current_baseline) + (alpha * new_sample) end |