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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb05adfa242cb60f47bd8dbe08da5e8c7d0250c450c7e9eee8b08b8a61f1670d
4
- data.tar.gz: 0ffabcd3c5423f52c0912dc68af62b6cd2a7d1de0c74ff6fd5cc1175413f100e
3
+ metadata.gz: b3e00594c33bb419f5ff6e62ee5fc995db3254c4c924c96fa442039bfd8bb8e2
4
+ data.tar.gz: 44878ab7e6dfb5051650957366b7af8ba12c7e3368cb18b40a7bb8b55ac2f758
5
5
  SHA512:
6
- metadata.gz: b3b3aba809104243badeeb0a18a9bccea0b6e49e34f1ce71b2f35c0d4f1f41718287858e6d400a869dd7ea4db9378448184084d81f4dec8363cdcc9cafce07d2
7
- data.tar.gz: 2719f1d43025b031b577289460272d7c340ca297cf49b4325e2e095e361db926fba7a85cf6b80ff6c973f5ee464b69545c1c4d43a45f48b517c8801eb46a3c54
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
- def initialize(interval: 10, limit: nil, &block)
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(limit: limit)
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
- @cluster.add(process_id)
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
- connections = @processes[process_id]
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)
@@ -6,7 +6,7 @@
6
6
  module Async
7
7
  module Container
8
8
  module Supervisor
9
- VERSION = "0.4.1"
9
+ VERSION = "0.5.0"
10
10
  end
11
11
  end
12
12
  end
@@ -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.1
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-27 00:00:00.000000000 Z
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.3'
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.3'
96
+ version: '0.5'
97
97
  executables: []
98
98
  extensions: []
99
99
  extra_rdoc_files: []
metadata.gz.sig CHANGED
Binary file