async-container-supervisor 0.4.1 → 0.5.0
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
- checksums.yaml.gz.sig +0 -0
- data/lib/async/container/supervisor/memory_monitor.rb +41 -16
- data/lib/async/container/supervisor/version.rb +1 -1
- data/lib/async/container/supervisor.rb +10 -0
- data.tar.gz.sig +0 -0
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3e00594c33bb419f5ff6e62ee5fc995db3254c4c924c96fa442039bfd8bb8e2
|
4
|
+
data.tar.gz: 44878ab7e6dfb5051650957366b7af8ba12c7e3368cb18b40a7bb8b55ac2f758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '078b5c42c1bf947f8da0129e7478be89df2ad109d20f408fb34368e00bd87335524713749e6e734f49459f5ce991700b09f0404ce6512191a883941d9c9e5944'
|
7
|
+
data.tar.gz: c471f47eab98de78180149969a052382f76f5ec10126352198aa62808e201a81b5d22beeeb1b3fe88a1b1ab84b6703f123e5d4addda2c3bfd55f52ee14f24893
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -10,25 +10,43 @@ module Async
|
|
10
10
|
module Container
|
11
11
|
module Supervisor
|
12
12
|
class MemoryMonitor
|
13
|
-
|
13
|
+
# Create a new memory monitor.
|
14
|
+
#
|
15
|
+
# @parameter interval [Integer] The interval at which to check for memory leaks.
|
16
|
+
# @parameter total_size_limit [Integer] The total size limit of all processes, or nil for no limit.
|
17
|
+
def initialize(interval: 10, total_size_limit: nil, **options)
|
14
18
|
@interval = interval
|
15
|
-
@cluster = Memory::Leak::Cluster.new(
|
19
|
+
@cluster = Memory::Leak::Cluster.new(total_size_limit: total_size_limit)
|
20
|
+
|
21
|
+
# We use these options when adding processes to the cluster:
|
22
|
+
@options = options
|
23
|
+
|
16
24
|
@processes = Hash.new{|hash, key| hash[key] = Set.new.compare_by_identity}
|
17
25
|
end
|
18
26
|
|
27
|
+
# Add a process to the memory monitor. You may override this to control how processes are added to the cluster.
|
28
|
+
#
|
29
|
+
# @parameter process_id [Integer] The process ID to add.
|
30
|
+
def add(process_id)
|
31
|
+
@cluster.add(process_id, **@options)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Register the connection (worker) with the memory monitor.
|
19
35
|
def register(connection)
|
36
|
+
Console.info(self, "Registering connection:", connection: connection, state: connection.state)
|
20
37
|
if process_id = connection.state[:process_id]
|
21
38
|
connections = @processes[process_id]
|
22
39
|
|
23
40
|
if connections.empty?
|
24
41
|
Console.info(self, "Registering process:", process_id: process_id)
|
25
|
-
|
42
|
+
self.add(process_id)
|
26
43
|
end
|
27
44
|
|
28
45
|
connections.add(connection)
|
29
46
|
end
|
30
47
|
end
|
31
48
|
|
49
|
+
# Remove the connection (worker) from the memory monitor.
|
32
50
|
def remove(connection)
|
33
51
|
if process_id = connection.state[:process_id]
|
34
52
|
connections = @processes[process_id]
|
@@ -42,28 +60,35 @@ module Async
|
|
42
60
|
end
|
43
61
|
end
|
44
62
|
|
63
|
+
# Dump the current status of the memory monitor.
|
64
|
+
#
|
65
|
+
# @parameter call [Connection::Call] The call to respond to.
|
45
66
|
def status(call)
|
46
67
|
call.push(memory_monitor: @cluster)
|
47
68
|
end
|
48
69
|
|
70
|
+
# Invoked when a memory leak is detected.
|
71
|
+
#
|
72
|
+
# @parameter process_id [Integer] The process ID of the process that has a memory leak.
|
73
|
+
# @parameter monitor [Memory::Leak::Monitor] The monitor that detected the memory leak.
|
74
|
+
# @returns [Boolean] True if the process was killed.
|
75
|
+
def memory_leak_detected(process_id, monitor)
|
76
|
+
Console.info(self, "Killing process:", process_id: process_id)
|
77
|
+
Process.kill(:INT, process_id)
|
78
|
+
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
# Run the memory monitor.
|
83
|
+
#
|
84
|
+
# @returns [Async::Task] The task that is running the memory monitor.
|
49
85
|
def run
|
50
86
|
Async do
|
51
87
|
while true
|
88
|
+
# This block must return true if the process was killed.
|
52
89
|
@cluster.check! do |process_id, monitor|
|
53
90
|
Console.error(self, "Memory leak detected in process:", process_id: process_id, monitor: monitor)
|
54
|
-
|
55
|
-
|
56
|
-
connections.each do |connection|
|
57
|
-
path = "/tmp/memory_dump_#{process_id}.json"
|
58
|
-
|
59
|
-
response = connection.call(do: :memory_dump, path: path, timeout: 30)
|
60
|
-
Console.info(self, "Memory dump saved to:", path, response: response)
|
61
|
-
@block.call(response) if @block
|
62
|
-
end
|
63
|
-
|
64
|
-
# Kill the process:
|
65
|
-
Console.info(self, "Killing process:", process_id: process_id)
|
66
|
-
Process.kill(:INT, process_id)
|
91
|
+
memory_leak_detected(process_id, monitor)
|
67
92
|
end
|
68
93
|
|
69
94
|
sleep(@interval)
|
@@ -13,3 +13,13 @@ require_relative "supervisor/memory_monitor"
|
|
13
13
|
|
14
14
|
require_relative "supervisor/environment"
|
15
15
|
require_relative "supervisor/supervised"
|
16
|
+
|
17
|
+
# @namespace
|
18
|
+
module Async
|
19
|
+
# @namespace
|
20
|
+
module Container
|
21
|
+
# @namespace
|
22
|
+
module Supervisor
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-container-supervisor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
37
37
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2025-02-
|
39
|
+
date: 2025-02-28 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: async-container
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.5'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.5'
|
97
97
|
executables: []
|
98
98
|
extensions: []
|
99
99
|
extra_rdoc_files: []
|
metadata.gz.sig
CHANGED
Binary file
|