Class: FastExists::Statistics::Tracker
- Inherits:
-
Object
- Object
- FastExists::Statistics::Tracker
- Defined in:
- lib/fast_exists/statistics/tracker.rb
Instance Attribute Summary collapse
-
#bloom_hits ⇒ Object
readonly
Returns the value of attribute bloom_hits.
-
#bloom_misses ⇒ Object
readonly
Returns the value of attribute bloom_misses.
-
#database_lookups ⇒ Object
readonly
Returns the value of attribute database_lookups.
-
#false_positives ⇒ Object
readonly
Returns the value of attribute false_positives.
-
#queries_avoided ⇒ Object
readonly
Returns the value of attribute queries_avoided.
Instance Method Summary collapse
- #false_positive_rate ⇒ Object
- #hit_ratio ⇒ Object
-
#initialize ⇒ Tracker
constructor
A new instance of Tracker.
- #miss_ratio ⇒ Object
- #record_avoided ⇒ Object
- #record_db_lookup ⇒ Object
- #record_false_positive ⇒ Object
- #record_hit ⇒ Object
- #reset! ⇒ Object
- #snapshot ⇒ Object
Constructor Details
#initialize ⇒ Tracker
Returns a new instance of Tracker.
10 11 12 13 |
# File 'lib/fast_exists/statistics/tracker.rb', line 10 def initialize @mutex = Mutex.new reset! end |
Instance Attribute Details
#bloom_hits ⇒ Object (readonly)
Returns the value of attribute bloom_hits.
8 9 10 |
# File 'lib/fast_exists/statistics/tracker.rb', line 8 def bloom_hits @bloom_hits end |
#bloom_misses ⇒ Object (readonly)
Returns the value of attribute bloom_misses.
8 9 10 |
# File 'lib/fast_exists/statistics/tracker.rb', line 8 def bloom_misses @bloom_misses end |
#database_lookups ⇒ Object (readonly)
Returns the value of attribute database_lookups.
8 9 10 |
# File 'lib/fast_exists/statistics/tracker.rb', line 8 def database_lookups @database_lookups end |
#false_positives ⇒ Object (readonly)
Returns the value of attribute false_positives.
8 9 10 |
# File 'lib/fast_exists/statistics/tracker.rb', line 8 def false_positives @false_positives end |
#queries_avoided ⇒ Object (readonly)
Returns the value of attribute queries_avoided.
8 9 10 |
# File 'lib/fast_exists/statistics/tracker.rb', line 8 def queries_avoided @queries_avoided end |
Instance Method Details
#false_positive_rate ⇒ Object
52 53 54 55 |
# File 'lib/fast_exists/statistics/tracker.rb', line 52 def false_positive_rate return 0.0 if @bloom_hits.zero? (@false_positives.to_f / @bloom_hits).round(4) end |
#hit_ratio ⇒ Object
40 41 42 43 44 |
# File 'lib/fast_exists/statistics/tracker.rb', line 40 def hit_ratio total = @bloom_hits + @bloom_misses return 0.0 if total.zero? (@bloom_hits.to_f / total).round(4) end |
#miss_ratio ⇒ Object
46 47 48 49 50 |
# File 'lib/fast_exists/statistics/tracker.rb', line 46 def miss_ratio total = @bloom_hits + @bloom_misses return 0.0 if total.zero? (@bloom_misses.to_f / total).round(4) end |
#record_avoided ⇒ Object
15 16 17 18 19 20 |
# File 'lib/fast_exists/statistics/tracker.rb', line 15 def record_avoided @mutex.synchronize do @queries_avoided += 1 @bloom_misses += 1 end end |
#record_db_lookup ⇒ Object
28 29 30 31 32 |
# File 'lib/fast_exists/statistics/tracker.rb', line 28 def record_db_lookup @mutex.synchronize do @database_lookups += 1 end end |
#record_false_positive ⇒ Object
34 35 36 37 38 |
# File 'lib/fast_exists/statistics/tracker.rb', line 34 def record_false_positive @mutex.synchronize do @false_positives += 1 end end |
#record_hit ⇒ Object
22 23 24 25 26 |
# File 'lib/fast_exists/statistics/tracker.rb', line 22 def record_hit @mutex.synchronize do @bloom_hits += 1 end end |
#reset! ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/fast_exists/statistics/tracker.rb', line 72 def reset! @mutex.synchronize do @queries_avoided = 0 @database_lookups = 0 @bloom_hits = 0 @bloom_misses = 0 @false_positives = 0 end end |
#snapshot ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fast_exists/statistics/tracker.rb', line 57 def snapshot @mutex.synchronize do { queries_avoided: @queries_avoided, database_lookups: @database_lookups, bloom_hits: @bloom_hits, bloom_misses: @bloom_misses, false_positives: @false_positives, hit_ratio: hit_ratio, miss_ratio: miss_ratio, false_positive_rate: false_positive_rate } end end |