Skip to content

Commit 6302e8d

Browse files
Disable memory sampler by default.
1 parent cd5c9c0 commit 6302e8d

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

lib/async/container/supervisor/memory_monitor.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ module Supervisor
1515
#
1616
# Uses the `memory` gem to track process memory and detect leaks.
1717
class MemoryMonitor
18-
MEMORY_SAMPLE = {duration: 30, timeout: 30*4}
19-
2018
# Create a new memory monitor.
2119
#
2220
# @parameter interval [Integer] The interval at which to check for memory leaks.
2321
# @parameter total_size_limit [Integer] The total size limit of all processes, or nil for no limit.
2422
# @parameter options [Hash] Options to pass to the cluster when adding processes.
25-
def initialize(interval: 10, total_size_limit: nil, memory_sample: MEMORY_SAMPLE, **options)
23+
def initialize(interval: 10, total_size_limit: nil, memory_sample: false, **options)
2624
@interval = interval
2725
@cluster = Memory::Leak::Cluster.new(total_size_limit: total_size_limit)
2826

lib/async/container/supervisor/worker.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,25 @@ def initialize(state = nil, endpoint: Supervisor.endpoint)
3232

3333
include Dispatchable
3434

35-
private def dump(call)
35+
private def dump(call, buffer: true)
3636
if path = call[:path]
3737
File.open(path, "w") do |file|
3838
yield file
3939
end
4040

4141
call.finish(path: path)
42-
else
42+
elsif buffer
4343
buffer = StringIO.new
4444
yield buffer
4545

46-
call.finish(data: buffer.string)
46+
if message = call[:log]
47+
Console.info(self, message, data: buffer.string)
48+
call.finish
49+
else
50+
call.finish(data: buffer.string)
51+
end
52+
else
53+
call.fail(error: {message: "Buffered output not supported!"})
4754
end
4855
end
4956

@@ -69,7 +76,7 @@ def do_scheduler_dump(call)
6976
def do_memory_dump(call)
7077
require "objspace"
7178

72-
dump(call) do |file|
79+
dump(call, buffer: false) do |file|
7380
ObjectSpace.dump_all(output: file)
7481
end
7582
end
@@ -109,13 +116,9 @@ def do_memory_sample(call)
109116

110117
report = sampler.report
111118

112-
# This is a temporary log to help with debugging:
113-
buffer = StringIO.new
114-
report.print(buffer)
115-
Console.info(self, "Memory sample completed.", report: buffer.string)
116-
117-
# Generate a report focused on retained objects (likely leaks):
118-
call.finish(report: report)
119+
dump(call) do |file|
120+
file.puts(report.to_s)
121+
end
119122
ensure
120123
GC.start
121124
end

releases.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Better handling of write failures in `Connection::Call.dispatch`, ensuring we don't leak calls.
66
- Robust monitor loop handling - restart on failure, and align loop iterations.
7+
- Disable memory sampler by default and use text output format.
8+
- Introduce support for redirecting dump output to logs.
79

810
## v0.8.0
911

test/async/container/supervisor.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def reader_target.dispatch(call)
7676
)
7777

7878
# Verify we got the forwarded response
79-
expect(result).to have_keys(:report)
80-
expect(result[:report]).to have_keys(:total_allocated, :total_retained)
79+
expect(result).to have_keys(:data)
8180
ensure
8281
client_conn&.close
8382
worker_task&.stop
@@ -117,8 +116,7 @@ def reader_target.dispatch(call); end
117116
result = connection.call(do: :memory_sample, duration: 1)
118117

119118
# The result should contain a report
120-
expect(result).to have_keys(:report)
121-
expect(result[:report]).to have_keys(:total_allocated, :total_retained)
119+
expect(result).to have_keys(:data)
122120
ensure
123121
worker_task&.stop
124122
end

0 commit comments

Comments
 (0)