rhcf-timeseries 0.0.5 → 0.0.6
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/lib/rhcf/timeseries/redis.rb +14 -14
- data/lib/rhcf/timeseries/version.rb +1 -1
- data/spec/lib/rhcf/timeseries/redis_spec.rb +73 -56
- data/spec/lib/rhcf/timeseries/result_spec.rb +30 -0
- data/spec/spec_helper.rb +0 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cef009b581b2e4025db5234bc0ba24cb970503d
|
4
|
+
data.tar.gz: 5168fbcf5b232d4bc3e2687be9b57e4efd6a1cca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2954a59ea1374b1308483c17480463ce3c3e9fc8c34881d9da4aae2728101f50ae44a666b41c0fe424c9475169fb872cf318cad1a771b2c72698fede5943141d
|
7
|
+
data.tar.gz: 6efdacb63cbc3f5f75a9b6568af314ba86f71b0555037daa36f673032de7480b023d3de7a50a1208911c43c9e510e63944d60ee2a281858fe8cd6f939bd7e91a
|
@@ -105,10 +105,14 @@ module Rhcf
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def better_resolution
|
108
|
-
span = @to - @from
|
108
|
+
span = @to.to_time - @from.to_time
|
109
|
+
|
109
110
|
resolutions = @series.resolutions.sort_by{|h| h[:span]}.reverse
|
110
|
-
|
111
|
-
|
111
|
+
5.downto(1) do |div|
|
112
|
+
res = resolutions.find{|r| r[:span] < span / div }
|
113
|
+
return res if res
|
114
|
+
end
|
115
|
+
return nil
|
112
116
|
end
|
113
117
|
end
|
114
118
|
|
@@ -152,12 +156,12 @@ module Rhcf
|
|
152
156
|
@connection_to_use || fail("No redis connection given")
|
153
157
|
end
|
154
158
|
|
155
|
-
def store(subject, event_point_hash, moment = Time.now)
|
159
|
+
def store(subject, event_point_hash, moment = Time.now, descend_subject = true, descend_event = true)
|
156
160
|
resolutions = resolutions_of(moment)
|
157
161
|
|
158
|
-
descend(subject) do |subject_path|
|
162
|
+
descend(subject, descend_subject) do |subject_path|
|
159
163
|
event_point_hash.each do |event, point_value|
|
160
|
-
descend(event) do |event_path|
|
164
|
+
descend(event, descend_event) do |event_path|
|
161
165
|
resolutions.each do |res|
|
162
166
|
resolution_name, resolution_value = *res
|
163
167
|
store_point_value(subject_path, event_path, resolution_name, resolution_value, point_value)
|
@@ -167,8 +171,6 @@ module Rhcf
|
|
167
171
|
end
|
168
172
|
end
|
169
173
|
|
170
|
-
|
171
|
-
|
172
174
|
def resolutions_of(moment)
|
173
175
|
@resolution_ids.collect do |res_id|
|
174
176
|
[res_id, resolution_value_at(moment, res_id)]
|
@@ -192,10 +194,10 @@ module Rhcf
|
|
192
194
|
end
|
193
195
|
end
|
194
196
|
|
195
|
-
def descend(path, &block)
|
197
|
+
def descend(path, do_descend = true , &block)
|
196
198
|
return if path.empty? or path == "."
|
197
199
|
block.call(path)
|
198
|
-
descend(File.dirname(path), &block)
|
200
|
+
descend(File.dirname(path), do_descend, &block) if do_descend
|
199
201
|
end
|
200
202
|
|
201
203
|
def store_point_event( resolution_name, resolution_value, subject_path, event_path)
|
@@ -252,13 +254,11 @@ module Rhcf
|
|
252
254
|
fail ArgumentError, "Invalid resolution name #{id} for this time series" if res.nil?
|
253
255
|
res.merge(:id => id)
|
254
256
|
end
|
257
|
+
|
255
258
|
def resolutions
|
256
|
-
@resolution_ids.
|
257
|
-
resolution(id)
|
258
|
-
end
|
259
|
+
@_resolutions ||= @resolution_ids.map { |id| resolution(id) }
|
259
260
|
end
|
260
261
|
|
261
|
-
|
262
262
|
def events_for_subject_on(subject, point, resolution_id)
|
263
263
|
key = [@prefix, 'event_set', resolution_id, point, subject].join(NAMESPACE_SEPARATOR)
|
264
264
|
logger.debug("EVENTSET SMEMBERS #{key}")
|
@@ -14,36 +14,52 @@ describe Rhcf::Timeseries::Redis do
|
|
14
14
|
subject.flush!
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
describe 'descending' do
|
18
|
+
it "is be fast to store and read" do
|
19
|
+
total = 0
|
20
|
+
start_time = Time.now
|
21
|
+
|
22
|
+
bench = Benchmark.measure {
|
23
|
+
StackProf.run(mode: :cpu, out: p('/tmp/stackprof-cpu-store-descend.dump')) do
|
24
|
+
1000.times do
|
25
|
+
total +=1
|
26
|
+
subject.store("a/b", {"e/f" => 1} ) #, time)
|
27
|
+
end
|
27
28
|
end
|
28
|
-
|
29
|
-
}
|
29
|
+
}
|
30
30
|
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
32
|
+
Benchmark.measure {
|
33
|
+
expect(subject.find("a", start_time - 11100, Time.now + 11100).total['e'].to_i).to eq(total)
|
34
|
+
}
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
Benchmark.measure {
|
37
|
+
expect(subject.find("a", start_time - 100000, Time.now + 100000).total(:year)['e/f'].to_i).to eq(total)
|
38
|
+
}
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
puts "Descend write speed %d points/seg | points:%d, duration:%0.3fs" % [speed = (1.0 * total / (bench.total + 0.00000001)), total, bench.total]
|
41
|
+
expect(speed).to be > 100
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe 'not descending' do
|
46
|
+
it "is be fast to store and read" do
|
47
|
+
total = 0
|
48
|
+
bench = Benchmark.measure {
|
49
|
+
StackProf.run(mode: :cpu, out: p('/tmp/stackprof-cpu-store-nodescend.dump')) do
|
50
|
+
10000.times do
|
51
|
+
total +=1
|
52
|
+
subject.store("a/b/c/d", {"e/f/g/h" => 1} , Time.now, false, false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
}
|
56
|
+
|
57
|
+
puts "No descend write speed %d points/seg | points:%d, duration:%0.3fs" % [new_speed = (1.0 * total / (bench.total + 0.00000001)), total, bench.total]
|
58
|
+
expect(new_speed).to be > 300
|
59
|
+
end
|
60
|
+
end
|
45
61
|
|
46
|
-
it "
|
62
|
+
it "is similar to redistat" do
|
47
63
|
start_time = Time.parse("2000-01-01 00:00:00")
|
48
64
|
Timecop.travel(start_time)
|
49
65
|
subject.store("views/product/15", {"web/firefox/3" => 1})
|
@@ -68,7 +84,7 @@ describe Rhcf::Timeseries::Redis do
|
|
68
84
|
Timecop.travel(15.minutes) #00:00:30
|
69
85
|
subject.store("views/product/11", {"web/chrome/11"=> 2})
|
70
86
|
|
71
|
-
subject.find("views/product", start_time, start_time + 55.minutes).total(:ever).
|
87
|
+
expect(subject.find("views/product", start_time, start_time + 55.minutes).total(:ever)).to eq({
|
72
88
|
"web" => 16.0,
|
73
89
|
"web/chrome" => 6.0,
|
74
90
|
"web/chrome/11" => 6.0,
|
@@ -77,9 +93,9 @@ describe Rhcf::Timeseries::Redis do
|
|
77
93
|
"web/ie" => 7.0,
|
78
94
|
"web/ie/5" => 2.0,
|
79
95
|
"web/ie/6" => 5.0
|
80
|
-
}
|
96
|
+
})
|
81
97
|
|
82
|
-
subject.find("views/product", start_time, start_time + 55.minutes).total(:year).
|
98
|
+
expect(subject.find("views/product", start_time, start_time + 55.minutes).total(:year)).to eq({
|
83
99
|
"web" => 16.0,
|
84
100
|
"web/chrome" => 6.0,
|
85
101
|
"web/chrome/11" => 6.0,
|
@@ -88,59 +104,60 @@ describe Rhcf::Timeseries::Redis do
|
|
88
104
|
"web/ie" => 7.0,
|
89
105
|
"web/ie/5" => 2.0,
|
90
106
|
"web/ie/6" => 5.0
|
91
|
-
}
|
107
|
+
})
|
92
108
|
|
93
|
-
subject.find("views/product", start_time, start_time + 55.minutes).total.
|
109
|
+
expect( subject.find("views/product", start_time, start_time + 55.minutes).total ).to eq({
|
94
110
|
'web' => 8,
|
95
111
|
'web/firefox' => 3,
|
96
112
|
'web/firefox/3' => 3,
|
97
113
|
'web/ie' => 5,
|
98
114
|
'web/ie/6' => 5,
|
99
|
-
}
|
115
|
+
})
|
100
116
|
|
101
|
-
subject.find("views/product/15", start_time, start_time + 55.minutes).points(:minute).
|
117
|
+
expect(subject.find("views/product/15", start_time, start_time + 55.minutes).points(:minute)).to eq([
|
102
118
|
{:moment=>"2000-01-01T00:00", :values=>{"web/firefox"=>1, "web/firefox/3"=>1, "web"=>1}},
|
103
119
|
{:moment=>"2000-01-01T00:30", :values=>{"web"=>3, "web/ie/6"=>3, "web/ie"=>3}},
|
104
120
|
{:moment=>"2000-01-01T00:45", :values=>{"web"=>2, "web/ie/6"=>2, "web/ie"=>2}}
|
105
|
-
]
|
121
|
+
])
|
106
122
|
|
107
|
-
subject.find("views/product/13", start_time, start_time + 55.minutes).points(:minute).
|
123
|
+
expect(subject.find("views/product/13", start_time, start_time + 55.minutes).points(:minute)).to eq([
|
108
124
|
{:moment=>"2000-01-01T00:15", :values=>{"web/firefox"=>2, "web/firefox/3"=>2, "web"=>2}},
|
109
|
-
]
|
110
|
-
|
125
|
+
])
|
111
126
|
|
112
|
-
|
113
|
-
|
114
|
-
subject.find("views/product", start_time, start_time + 55.minutes).points(:minute).should == [
|
127
|
+
expect(subject.find("views/product", start_time, start_time + 55.minutes).points(:minute)).to eq([
|
115
128
|
{:moment=>"2000-01-01T00:00", :values=>{"web/firefox"=>1, "web/firefox/3"=>1, "web"=>1}},
|
116
129
|
{:moment=>"2000-01-01T00:15", :values=>{"web/firefox"=>2, "web/firefox/3"=>2, "web"=>2}},
|
117
130
|
{:moment=>"2000-01-01T00:30", :values=>{"web"=>3, "web/ie/6"=>3, "web/ie"=>3}},
|
118
131
|
{:moment=>"2000-01-01T00:45", :values=>{"web"=>2, "web/ie/6"=>2, "web/ie"=>2}}
|
119
|
-
]
|
132
|
+
])
|
120
133
|
|
121
|
-
subject.find("views", start_time, start_time + 55.minutes).points(:minute).
|
134
|
+
expect(subject.find("views", start_time, start_time + 55.minutes).points(:minute)).to eq([
|
122
135
|
{:moment=>"2000-01-01T00:00", :values=>{"web/firefox"=>1, "web/firefox/3"=>1, "web"=>1}},
|
123
136
|
{:moment=>"2000-01-01T00:15", :values=>{"web/firefox"=>2, "web/firefox/3"=>2, "web"=>2}},
|
124
137
|
{:moment=>"2000-01-01T00:30", :values=>{"web"=>3, "web/ie/6"=>3, "web/ie"=>3}},
|
125
138
|
{:moment=>"2000-01-01T00:45", :values=>{"web"=>2, "web/ie/6"=>2, "web/ie"=>2}}
|
126
|
-
]
|
127
|
-
|
128
|
-
subject.find("views", start_time).points(:hour).
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
139
|
+
])
|
140
|
+
|
141
|
+
expect(subject.find("views", start_time).points(:hour)).to eq([
|
142
|
+
{
|
143
|
+
:moment=>"2000-01-01T00",
|
144
|
+
:values=> {
|
145
|
+
"web/ie"=>5.0,
|
146
|
+
"web"=>8.0,
|
147
|
+
"web/firefox"=>3.0,
|
148
|
+
"web/ie/6"=>5.0,
|
149
|
+
"web/firefox/3"=>3.0}
|
150
|
+
},{
|
151
|
+
:moment=>"2000-01-01T01",
|
152
|
+
:values=>{
|
153
|
+
"web/ie"=>2.0,
|
154
|
+
"web/chrome"=>6.0,
|
155
|
+
"web/chrome/11"=>6.0,
|
156
|
+
"web"=>8.0,
|
157
|
+
"web/ie/5"=>2.0
|
158
|
+
}
|
159
|
+
}
|
160
|
+
])
|
144
161
|
end
|
145
162
|
|
146
163
|
it "causes no stack overflow" do
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhcf/timeseries/redis'
|
3
|
+
|
4
|
+
|
5
|
+
describe "Query" do
|
6
|
+
describe "#better_resolution" do
|
7
|
+
|
8
|
+
let(:redis_connection){nil}
|
9
|
+
describe "When having a smaller then 1/5 " do
|
10
|
+
let(:series) { Rhcf::Timeseries::Redis.new(nil, redis_connection, resolutions: [:hour, :"15minutes", :minute]) }
|
11
|
+
it { expect(series.find('bla', Time.now - 3600, Time.now).better_resolution[:id]).to eq :minute }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "When having a smaller but greather then 1/5" do
|
15
|
+
let(:series) { Rhcf::Timeseries::Redis.new(nil, redis_connection, resolutions: [:hour, :"15minutes"]) }
|
16
|
+
it { expect(series.find('bla', Time.now - 3600, Time.now).better_resolution[:id]).to eq :"15minutes" }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "When having no smaller, only its size" do
|
20
|
+
let(:series) { Rhcf::Timeseries::Redis.new(nil, redis_connection, resolutions: [:hour]) }
|
21
|
+
it { expect(series.find('bla', DateTime.parse('2015-01-01 01:50:00'), DateTime.parse('2015-01-01 03:10:00')).better_resolution[:id]).to eq :hour }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "When having only bigger" do
|
25
|
+
let(:series) { Rhcf::Timeseries::Redis.new(nil, redis_connection, resolutions: [:month]) }
|
26
|
+
it { expect(series.find('bla', DateTime.parse('2015-01-01 01:50:00'), DateTime.parse('2015-01-01 03:10:00')).better_resolution).to be_nil}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcf-timeseries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romeu Fonseca
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- rhcf-timeseries.gemspec
|
117
117
|
- spec/lib/rhcf/timeseries/TODO
|
118
118
|
- spec/lib/rhcf/timeseries/redis_spec.rb
|
119
|
+
- spec/lib/rhcf/timeseries/result_spec.rb
|
119
120
|
- spec/spec_helper.rb
|
120
121
|
homepage: ''
|
121
122
|
licenses:
|
@@ -144,4 +145,5 @@ summary: Redistat inspired redis time series.
|
|
144
145
|
test_files:
|
145
146
|
- spec/lib/rhcf/timeseries/TODO
|
146
147
|
- spec/lib/rhcf/timeseries/redis_spec.rb
|
148
|
+
- spec/lib/rhcf/timeseries/result_spec.rb
|
147
149
|
- spec/spec_helper.rb
|