pesto 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/examples/aggressive.rb +1 -1
- data/lib/pesto/lock.rb +34 -17
- data/lib/pesto/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548db411d5cb5f639bc299add68aa29af743b2f3
|
4
|
+
data.tar.gz: 63a79d43327c3419a882e2faea5f5aadca73f6b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f9c0677b515a53aa0ca1b12b920a6ee1265240b701f9ebb5f8ed9fb9dce88250e0e96a3719e7ba3a680fdd93bcd8cc0be078f92546893646556033fea4db51
|
7
|
+
data.tar.gz: 15106012331ba282174c90108c7877e419d88f112f06ad1c172c3a2179abaff01f00a3d31a2fb0495de027d538e652a18ff7a9545ec902681e793de8a632e9ed
|
data/Gemfile.lock
CHANGED
data/examples/aggressive.rb
CHANGED
@@ -49,7 +49,7 @@ for pid in 0..$concurrency
|
|
49
49
|
redis = ConnectionPool.new(size: 5, :timeout => 10) { Redis.new(:driver => :hiredis) }
|
50
50
|
while true do
|
51
51
|
lock({ :pool => redis }, pfx, pid)
|
52
|
-
if
|
52
|
+
if $use_sleep
|
53
53
|
delay = rand(1000).to_f / 10000.0
|
54
54
|
sleep delay
|
55
55
|
end
|
data/lib/pesto/lock.rb
CHANGED
@@ -12,6 +12,28 @@ module Pesto
|
|
12
12
|
:timeout_lock => 1,
|
13
13
|
:interval_check => 0.05
|
14
14
|
}.merge(opts)
|
15
|
+
|
16
|
+
load_scripts
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_scripts
|
20
|
+
cp.with do |rc|
|
21
|
+
@script_sha = rc.script(
|
22
|
+
:load,
|
23
|
+
"local timeout = tonumber(ARGV[1])
|
24
|
+
assert(type(timeout) == 'number', 'timeout expects a number') \
|
25
|
+
|
26
|
+
if redis.call('setnx', KEYS[1], 1) == 1 then \
|
27
|
+
if tonumber(ARGV[1]) > -1 then \
|
28
|
+
redis.call('expire', KEYS[1], timeout) \
|
29
|
+
end
|
30
|
+
return 1 \
|
31
|
+
else \
|
32
|
+
return 0 \
|
33
|
+
end"
|
34
|
+
)
|
35
|
+
puts @script_sha
|
36
|
+
end
|
15
37
|
end
|
16
38
|
|
17
39
|
def conf
|
@@ -33,14 +55,14 @@ module Pesto
|
|
33
55
|
|
34
56
|
names = (_names.is_a?(String) ? [_names] : _names).uniq
|
35
57
|
opts[:timeout_lock_expire] = opts[:timeout_lock_expire].to_i
|
36
|
-
opts[:timeout_lock_expire] += opts[:timeout_lock] * names.size
|
58
|
+
opts[:timeout_lock_expire] += (opts[:timeout_lock] * names.size).ceil.to_i
|
37
59
|
|
38
60
|
t_start = Time.now
|
39
61
|
|
40
62
|
while true
|
41
|
-
res, locks, stop = get_locks names
|
42
|
-
|
43
|
-
|
63
|
+
res, locks, stop = get_locks names, {
|
64
|
+
:timeout_lock_expire => opts[:timeout_lock_expire]
|
65
|
+
}
|
44
66
|
|
45
67
|
break if stop || (Time.now - t_start) > opts[:timeout_lock]
|
46
68
|
|
@@ -51,30 +73,25 @@ module Pesto
|
|
51
73
|
stop ? 1 : 0
|
52
74
|
end
|
53
75
|
|
54
|
-
def
|
55
|
-
cp.with do |rc|
|
56
|
-
rc.pipelined do
|
57
|
-
names.each do |n|
|
58
|
-
rc.expire lock_hash(n), opts[:timeout_lock_expire].to_i
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def get_locks names
|
76
|
+
def get_locks names, opts = {}
|
65
77
|
locked = 0
|
66
78
|
locks = []
|
67
79
|
res = []
|
68
80
|
|
81
|
+
timeout_lock_expire = conf[:lock_expire] ? opts[:timeout_lock_expire] : -1
|
82
|
+
|
69
83
|
cp.with do |rc|
|
70
84
|
res = rc.pipelined do
|
71
85
|
names.each do |n|
|
72
|
-
rc.
|
86
|
+
rc.evalsha(@script_sha, {
|
87
|
+
:keys => [lock_hash(n)],
|
88
|
+
:argv => [timeout_lock_expire]
|
89
|
+
})
|
73
90
|
end
|
74
91
|
end
|
75
92
|
|
76
93
|
names.each_with_index do |n, ix|
|
77
|
-
next
|
94
|
+
next if res[ix] != 1
|
78
95
|
locked += 1
|
79
96
|
locks.push n
|
80
97
|
end
|
data/lib/pesto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pesto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bfx devs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hiredis
|