splitclient-rb 7.3.5.pre.rc1-java → 7.3.5.pre.rc4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/splitclient-rb/cache/filter/bloom_filter.rb +63 -0
- data/lib/splitclient-rb/cache/filter/filter_adapter.rb +2 -2
- data/lib/splitclient-rb/engine/common/impressions_manager.rb +8 -4
- data/lib/splitclient-rb/split_factory.rb +2 -5
- data/lib/splitclient-rb/version.rb +1 -1
- data/lib/splitclient-rb.rb +1 -0
- data/splitclient-rb.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 056032ef5843a8944e848f07d7a75471a193bdba
|
4
|
+
data.tar.gz: 94812fea82d41a99a9537555e3b04f617215807d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b792cec62ca90569dbed5bcc8b4bb1a8bd3774add314806c0dc4fa10a09e560fbacf3927453348812f53fffdf88016a60b22fb47c4bb7bbf74d3cbdffd4e27d
|
7
|
+
data.tar.gz: 5b1e2eecf0de9f94bb6248eb145dc206f5927c2a0e068f2c3aeea57894ec358e9afec70409f5f109e3ed67e8de71b89317bc71d5abafa63861d7195e8e9a5c3f
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bitarray'
|
4
|
+
|
5
|
+
module SplitIoClient
|
6
|
+
module Cache
|
7
|
+
module Filter
|
8
|
+
class BloomFilter
|
9
|
+
def initialize(capacity, false_positive_probability = 0.001)
|
10
|
+
@capacity = capacity.round
|
11
|
+
m = best_m(capacity, false_positive_probability)
|
12
|
+
@ba = BitArray.new(m.round)
|
13
|
+
@k = best_k(capacity)
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(string)
|
17
|
+
return false if contains?(string)
|
18
|
+
|
19
|
+
positions = hashes(string)
|
20
|
+
|
21
|
+
positions.each { |position| @ba[position] = 1 }
|
22
|
+
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def contains?(string)
|
27
|
+
!hashes(string).any? { |ea| @ba[ea] == 0 }
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear
|
31
|
+
@ba.size.times { |i| @ba[i] = 0 }
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# m is the required number of bits in the array
|
37
|
+
def best_m(capacity, false_positive_probability)
|
38
|
+
-(capacity * Math.log(false_positive_probability)) / (Math.log(2) ** 2)
|
39
|
+
end
|
40
|
+
|
41
|
+
# k is the number of hash functions that minimizes the probability of false positives
|
42
|
+
def best_k(capacity)
|
43
|
+
(Math.log(2) * (@ba.size / capacity)).round
|
44
|
+
end
|
45
|
+
|
46
|
+
def hashes(data)
|
47
|
+
m = @ba.size
|
48
|
+
h = Digest::MD5.hexdigest(data.to_s).to_i(16)
|
49
|
+
x = h % m
|
50
|
+
h /= m
|
51
|
+
y = h % m
|
52
|
+
h /= m
|
53
|
+
z = h % m
|
54
|
+
[x] + 1.upto(@k - 1).collect do |i|
|
55
|
+
x = (x + y) % m
|
56
|
+
y = (y + z) % m
|
57
|
+
x
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -10,13 +10,13 @@ module SplitIoClient
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def add(feature_name, key)
|
13
|
-
@filter.
|
13
|
+
@filter.add("#{feature_name}#{key}")
|
14
14
|
rescue StandardError => e
|
15
15
|
@config.log_found_exception(__method__.to_s, e)
|
16
16
|
end
|
17
17
|
|
18
18
|
def contains?(feature_name, key)
|
19
|
-
@filter.
|
19
|
+
@filter.contains?("#{feature_name}#{key}")
|
20
20
|
rescue StandardError => e
|
21
21
|
@config.log_found_exception(__method__.to_s, e)
|
22
22
|
end
|
@@ -9,15 +9,13 @@ module SplitIoClient
|
|
9
9
|
impression_counter,
|
10
10
|
telemetry_runtime_producer,
|
11
11
|
impression_observer,
|
12
|
-
unique_keys_tracker
|
13
|
-
impression_router)
|
12
|
+
unique_keys_tracker)
|
14
13
|
@config = config
|
15
14
|
@impressions_repository = impressions_repository
|
16
15
|
@impression_counter = impression_counter
|
17
16
|
@impression_observer = impression_observer
|
18
17
|
@telemetry_runtime_producer = telemetry_runtime_producer
|
19
18
|
@unique_keys_tracker = unique_keys_tracker
|
20
|
-
@impression_router = impression_router
|
21
19
|
end
|
22
20
|
|
23
21
|
def build_impression(matching_key, bucketing_key, split_name, treatment, params = {})
|
@@ -58,12 +56,18 @@ module SplitIoClient
|
|
58
56
|
@config.log_found_exception(__method__.to_s, e)
|
59
57
|
ensure
|
60
58
|
record_stats(stats)
|
61
|
-
|
59
|
+
impression_router.add_bulk(impressions)
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
65
63
|
private
|
66
64
|
|
65
|
+
def impression_router
|
66
|
+
@impression_router ||= SplitIoClient::ImpressionRouter.new(@config)
|
67
|
+
rescue StandardError => error
|
68
|
+
@config.log_found_exception(__method__.to_s, error)
|
69
|
+
end
|
70
|
+
|
67
71
|
def record_stats(stats)
|
68
72
|
return if redis?
|
69
73
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'bloomfilter-rb'
|
4
|
-
|
5
3
|
module SplitIoClient
|
6
4
|
class SplitFactory
|
7
5
|
ROOT_PROCESS_ID = Process.pid
|
@@ -218,7 +216,7 @@ module SplitIoClient
|
|
218
216
|
return
|
219
217
|
end
|
220
218
|
|
221
|
-
bf = BloomFilter
|
219
|
+
bf = Cache::Filter::BloomFilter.new(30_000_000)
|
222
220
|
filter_adapter = Cache::Filter::FilterAdapter.new(@config, bf)
|
223
221
|
cache = Concurrent::Hash.new
|
224
222
|
@unique_keys_tracker = Engine::Impressions::UniqueKeysTracker.new(@config, filter_adapter, @impressions_sender_adapter, cache)
|
@@ -251,8 +249,7 @@ module SplitIoClient
|
|
251
249
|
build_impressions_observer
|
252
250
|
build_impression_counter
|
253
251
|
|
254
|
-
|
255
|
-
@impressions_manager = Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer, @impression_observer, @unique_keys_tracker, impression_router)
|
252
|
+
@impressions_manager = Engine::Common::ImpressionManager.new(@config, @impressions_repository, @impression_counter, @runtime_producer, @impression_observer, @unique_keys_tracker)
|
256
253
|
end
|
257
254
|
end
|
258
255
|
end
|
data/lib/splitclient-rb.rb
CHANGED
@@ -12,6 +12,7 @@ require 'splitclient-rb/cache/adapters/memory_adapter'
|
|
12
12
|
require 'splitclient-rb/cache/adapters/redis_adapter'
|
13
13
|
require 'splitclient-rb/cache/fetchers/segment_fetcher'
|
14
14
|
require 'splitclient-rb/cache/fetchers/split_fetcher'
|
15
|
+
require 'splitclient-rb/cache/filter/bloom_filter'
|
15
16
|
require 'splitclient-rb/cache/filter/filter_adapter'
|
16
17
|
require 'splitclient-rb/cache/hashers/impression_hasher'
|
17
18
|
require 'splitclient-rb/cache/observers/impression_observer'
|
data/splitclient-rb.gemspec
CHANGED
@@ -50,7 +50,7 @@ Gem::Specification.new do |spec|
|
|
50
50
|
spec.add_development_dependency 'timecop', '~> 0.9'
|
51
51
|
spec.add_development_dependency 'webmock', '~> 3.14'
|
52
52
|
|
53
|
-
spec.add_runtime_dependency '
|
53
|
+
spec.add_runtime_dependency 'bitarray', '~> 1.3'
|
54
54
|
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
55
55
|
spec.add_runtime_dependency 'faraday', '>= 0.8', '< 2.0'
|
56
56
|
spec.add_runtime_dependency 'json', '>= 1.8', '< 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splitclient-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.3.5.pre.
|
4
|
+
version: 7.3.5.pre.rc4
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Split Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,15 +197,15 @@ dependencies:
|
|
197
197
|
requirements:
|
198
198
|
- - "~>"
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
version: '
|
201
|
-
name:
|
200
|
+
version: '1.3'
|
201
|
+
name: bitarray
|
202
202
|
prerelease: false
|
203
203
|
type: :runtime
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: '
|
208
|
+
version: '1.3'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
requirement: !ruby/object:Gem::Requirement
|
211
211
|
requirements:
|
@@ -402,6 +402,7 @@ files:
|
|
402
402
|
- lib/splitclient-rb/cache/adapters/redis_adapter.rb
|
403
403
|
- lib/splitclient-rb/cache/fetchers/segment_fetcher.rb
|
404
404
|
- lib/splitclient-rb/cache/fetchers/split_fetcher.rb
|
405
|
+
- lib/splitclient-rb/cache/filter/bloom_filter.rb
|
405
406
|
- lib/splitclient-rb/cache/filter/filter_adapter.rb
|
406
407
|
- lib/splitclient-rb/cache/hashers/impression_hasher.rb
|
407
408
|
- lib/splitclient-rb/cache/observers/impression_observer.rb
|