stack-service-base 0.0.20 → 0.0.21
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/stack-service-base/fiber_pool.rb +23 -21
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57b5474b1774d7f28bad212eef759c57005c33c905e7a84cf8ef2ffd703456a5
|
4
|
+
data.tar.gz: 2ec3fe1f5b677cc6d5470eb27917a76bd05d0ae77cfa9119de139399e003a4f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f65f78c9ddd2261bc215aca0692774b148f968236b9c2cbb767b3b0c43832adc049f96ab9a79d98d6b7c7d1c5ab96ca987398e980daed7646b9f8448cbc8a90a
|
7
|
+
data.tar.gz: fa2192cfce9208ac0c72f46c0d75383fdb4f0d73f3cc93d75c24e87ae4398d480857e050502aa9052af8f125092103183b3f90abaf7b1a659dfbf614e0bc61a7
|
@@ -2,29 +2,31 @@ require 'sequel'
|
|
2
2
|
require 'async/semaphore'
|
3
3
|
# $stdout.sync = true
|
4
4
|
|
5
|
+
$local_log = -> msg do
|
6
|
+
otl_current_span{ |span|
|
7
|
+
span.add_event("FiberPool", attributes: {
|
8
|
+
F: Fiber.current.__id__, T: Thread.current.__id__, A: self.__id__,
|
9
|
+
message: msg
|
10
|
+
}.transform_keys(&:to_s) )
|
11
|
+
}
|
12
|
+
|
13
|
+
return if defined? PERFORMANCE
|
14
|
+
$stdout.puts "F:#{Fiber.current.__id__} : T:#{Thread.current.__id__} : A:#{self.__id__} : #{msg}"
|
15
|
+
# LOGGER.debug :fiber_pool, msg
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
5
20
|
class FiberConnectionPool < Sequel::ConnectionPool
|
6
21
|
VALIDATION_TIMEOUT = 20
|
7
22
|
POOL_SIZE = 10
|
8
23
|
|
9
|
-
def log(msg)
|
10
|
-
otl_current_span{ |span|
|
11
|
-
span.add_event("FiberPool", attributes: {
|
12
|
-
F: Fiber.current.__id__, T: Thread.current.__id__, A: self.__id__,
|
13
|
-
message: msg
|
14
|
-
}.transform_keys(&:to_s) )
|
15
|
-
}
|
16
|
-
|
17
|
-
return if defined? PERFORMANCE
|
18
|
-
$stdout.puts "F:#{Fiber.current.__id__} : T:#{Thread.current.__id__} : A:#{self.__id__} : #{msg}"
|
19
|
-
# LOGGER.debug :fiber_pool, msg
|
20
|
-
end
|
21
|
-
|
22
24
|
def initialize(db, opts = OPTS)
|
23
25
|
otl_span "FiberConnectionPool.initialize" do |span|
|
24
26
|
super
|
25
27
|
@allocator = ->() {
|
26
28
|
make_new(:default).tap { |conn|
|
27
|
-
|
29
|
+
$local_log["new connection (fiber pool) #{conn}"]
|
28
30
|
}
|
29
31
|
}
|
30
32
|
@stock = []
|
@@ -44,7 +46,7 @@ class FiberConnectionPool < Sequel::ConnectionPool
|
|
44
46
|
|
45
47
|
def hold(_server = nil)
|
46
48
|
return yield @acquired[Fiber.current] if @acquired[Fiber.current] # protect from recursion
|
47
|
-
|
49
|
+
$local_log["hold in (fiber pool: #{__id__}) #{@stock.map{_1.__id__}}"]
|
48
50
|
fiber = Fiber.current
|
49
51
|
try_count = 2
|
50
52
|
|
@@ -60,19 +62,19 @@ class FiberConnectionPool < Sequel::ConnectionPool
|
|
60
62
|
yield @acquired[fiber]
|
61
63
|
|
62
64
|
rescue Sequel::DatabaseDisconnectError => e
|
63
|
-
|
65
|
+
$local_log["remove connection (fiber pool) retry(#{try_count})"]
|
64
66
|
@acquired.delete(fiber)
|
65
67
|
(try_count -=1) < 0 ? raise : retry
|
66
68
|
|
67
69
|
rescue =>e
|
68
70
|
$stdout.puts e.message
|
69
71
|
$stdout.puts e.backtrace[0..10].join "\n"
|
70
|
-
|
72
|
+
$local_log['remove connection (fiber pool) give up']
|
71
73
|
@acquired.delete(fiber)
|
72
74
|
raise
|
73
75
|
ensure
|
74
76
|
@stock.push @acquired.delete(fiber) if @acquired[fiber]
|
75
|
-
|
77
|
+
$local_log["hold out (fiber pool: #{__id__}) #{@stock.map{_1.__id__}}"]
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
@@ -81,7 +83,7 @@ class FiberConnectionPool < Sequel::ConnectionPool
|
|
81
83
|
# def preconnect(_concurrent = false) = :unimplemented
|
82
84
|
def disconnect(symbol)
|
83
85
|
until @stock.empty?
|
84
|
-
|
86
|
+
$local_log['disconnect connection (fiber pool)']
|
85
87
|
@stock.shift.close
|
86
88
|
end
|
87
89
|
end
|
@@ -100,10 +102,10 @@ require 'sequel/adapters/postgres'
|
|
100
102
|
class Sequel::Postgres::Adapter
|
101
103
|
def execute_query(sql, args)
|
102
104
|
$stdout.puts "F:#{Fiber.current.__id__} : T:#{Thread.current.__id__} : A:#{self.__id__} : #{sql[0..60]}" unless defined? PERFORMANCE
|
103
|
-
|
105
|
+
$local_log["query: #{sql.slice(0, 60)}"]
|
104
106
|
@db.log_connection_yield(sql, self, args){args ? async_exec_params(sql, args) : async_exec(sql)}
|
105
107
|
rescue => e
|
106
|
-
|
108
|
+
$local_log["Error: #{e.message}"]
|
107
109
|
$stdout.puts e.message
|
108
110
|
raise
|
109
111
|
end
|
data/lib/version.rb
CHANGED