nyxis 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/pattern.rb +69 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 870517a00ae147fbd6b3a894b3048c0dc9e49681ff63cfc17d9d349b8538a627
|
|
4
|
+
data.tar.gz: ba83e8a5fe9c7b55cae2f7f55f5ce6275adfbcc7bcdeab18888ea811fae90690
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a410795cd0d7fea406c140593022d55a6d9eeae978c79f94503f73da103fbe38650e71cd7fbbc67652c98b17a788bdcf52995e73f912f42cf5448fd9367b6d2d
|
|
7
|
+
data.tar.gz: 3fe99bec18a583afca214edfe00484161993e456a38b2df1217bdca929c0a0c546611b609c84a654893b92ee1157f866dd1d7aa5cf4226793278796ea39173e1
|
data/pattern.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Access pattern detector (Adaptive-prefetch-spec §4).
|
|
4
|
+
|
|
5
|
+
module Nxs
|
|
6
|
+
SEQUENTIAL_THRESHOLD = 10
|
|
7
|
+
RANDOM_THRESHOLD = 100
|
|
8
|
+
HISTORY_SIZE = 32
|
|
9
|
+
MIN_OBSERVATIONS = 8
|
|
10
|
+
UPGRADE_SEQUENTIAL_THRESHOLD = 100
|
|
11
|
+
|
|
12
|
+
PATTERN_UNKNOWN = 'unknown'
|
|
13
|
+
PATTERN_SEQUENTIAL = 'sequential'
|
|
14
|
+
PATTERN_RANDOM = 'random'
|
|
15
|
+
PATTERN_MIXED = 'mixed'
|
|
16
|
+
|
|
17
|
+
# Observes record(index) / seek calls and classifies access patterns.
|
|
18
|
+
class AccessPatternDetector
|
|
19
|
+
def initialize
|
|
20
|
+
@accesses = Array.new(HISTORY_SIZE, -1)
|
|
21
|
+
@write_pos = 0
|
|
22
|
+
@filled = 0
|
|
23
|
+
@sequential_runs = 0
|
|
24
|
+
@random_jumps = 0
|
|
25
|
+
@last_index = -1
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
attr_reader :sequential_runs, :last_index
|
|
29
|
+
|
|
30
|
+
def observe(index)
|
|
31
|
+
idx = index
|
|
32
|
+
if @last_index >= 0
|
|
33
|
+
delta = (idx - @last_index).abs
|
|
34
|
+
if delta <= SEQUENTIAL_THRESHOLD
|
|
35
|
+
@sequential_runs = [@sequential_runs + 1, 0xffffffff].min
|
|
36
|
+
elsif delta > RANDOM_THRESHOLD
|
|
37
|
+
@random_jumps = [@random_jumps + 1, 0xffffffff].min
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
@accesses[@write_pos] = idx
|
|
41
|
+
@write_pos = (@write_pos + 1) % HISTORY_SIZE
|
|
42
|
+
@filled += 1 if @filled < HISTORY_SIZE
|
|
43
|
+
@last_index = idx
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def pattern
|
|
47
|
+
total = @sequential_runs + @random_jumps
|
|
48
|
+
return PATTERN_UNKNOWN if total < MIN_OBSERVATIONS
|
|
49
|
+
|
|
50
|
+
return PATTERN_SEQUENTIAL if @sequential_runs > @random_jumps * 3
|
|
51
|
+
return PATTERN_RANDOM if @random_jumps > @sequential_runs
|
|
52
|
+
|
|
53
|
+
PATTERN_MIXED
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Predicted next record indices when pattern is sequential (§4.4).
|
|
57
|
+
def predict_next(depth, record_count)
|
|
58
|
+
return [] unless pattern == PATTERN_SEQUENTIAL && @last_index >= 0
|
|
59
|
+
|
|
60
|
+
start = @last_index + 1
|
|
61
|
+
out = []
|
|
62
|
+
depth.times do |i|
|
|
63
|
+
idx = start + i
|
|
64
|
+
out << idx if idx < record_count
|
|
65
|
+
end
|
|
66
|
+
out
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nyxis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Micael Malta
|
|
@@ -23,6 +23,7 @@ files:
|
|
|
23
23
|
- LICENSE
|
|
24
24
|
- README.md
|
|
25
25
|
- nxs.rb
|
|
26
|
+
- pattern.rb
|
|
26
27
|
homepage: https://github.com/nyxis-io/nyxis-drivers
|
|
27
28
|
licenses:
|
|
28
29
|
- BUSL-1.1
|