You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# @attribute [Numeric | Nil] The memory limit for the cluster.
38
-
attr_accessor:limit
39
+
# @attribute [Numeric | Nil] The total size of the cluster.
40
+
attr:total_size
41
+
42
+
# @attribute [Numeric | Nil] The total size limit for the cluster, in bytes, if which is exceeded, the cluster will terminate processes.
43
+
attr_accessor:total_size_limit
39
44
40
45
# @attribute [Hash(Integer, Monitor)] The process IDs and monitors in the cluster.
41
46
attr:processes
@@ -53,37 +58,47 @@ def remove(process_id)
53
58
# Apply the memory limit to the cluster. If the total memory usage exceeds the limit, yields each process ID and monitor in order of maximum memory usage, so that they could be terminated and/or removed.
54
59
#
55
60
# @yields {|process_id, monitor| ...} each process ID and monitor in order of maximum memory usage, return true if it was terminated to adjust memory usage.
Copy file name to clipboardExpand all lines: lib/memory/leak/monitor.rb
+73-56Lines changed: 73 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -7,48 +7,50 @@
7
7
8
8
moduleMemory
9
9
moduleLeak
10
-
# Detects memory leaks by tracking heap size increases.
10
+
# Detects memory leaks by tracking process size increases.
11
11
#
12
12
# A memory leak is characterised by the memory usage of the application continuing to rise over time. We can detect this by sampling memory usage and comparing it to the previous sample. If the memory usage is higher than the previous sample, we can say that the application has allocated more memory. Eventually we expect to see this stabilize, but if it continues to rise, we can say that the application has a memory leak.
13
13
#
14
14
# We should be careful not to filter historical data, as some memory leaks may only become apparent after a long period of time. Any kind of filtering may prevent us from detecting such a leak.
15
15
classMonitor
16
-
# We only track heap size changes greater than this threshold, across the DEFAULT_INTERVAL.
17
-
# True memory leaks will eventually hit this threshold, while small fluctuations will not.
18
-
DEFAULT_THRESHOLD=1024*1024*10
16
+
# We only track process size changes greater than this threshold_size, across the DEFAULT_INTERVAL.
17
+
# True memory leaks will eventually hit this threshold_size, while small fluctuations will not.
18
+
DEFAULT_THRESHOLD_SIZE=1024*1024*10
19
19
20
-
# We track the last N heap size increases.
21
-
# If the heap size is not stabilizing within the specified limit, we can assume there is a leak.
22
-
# With a default interval of 10 seconds, this will track the last ~3 minutes of heap size increases.
23
-
DEFAULT_LIMIT=20
20
+
# We track the last N process size increases.
21
+
# If the process size is not stabilizing within the specified increase_limit, we can assume there is a leak.
22
+
# With a default interval of 10 seconds, this will track the last ~3 minutes of process size increases.
23
+
DEFAULT_INCREASE_LIMIT=20
24
24
25
25
# Create a new monitor.
26
26
#
27
-
# @parameter maximum [Numeric] The initial maximum heap size, from which we willl track increases, in bytes.
28
-
# @parameter threshold [Numeric] The threshold for heap size increases, in bytes.
29
-
# @parameter limit [Numeric] The limit for the number of heap size increases, before we assume a memory leak.
# @returns [Hash] A serializable representation of the cluster.
44
45
defas_json(...)
45
46
{
46
47
process_id: @process_id,
47
-
current: @current,
48
-
maximum: @maximum,
49
-
threshold: @threshold,
50
-
limit: @limit,
51
-
count: @count,
48
+
current_size: @current_size,
49
+
maximum_size: @maximum_size,
50
+
maximum_size_limit: @maximum_size_limit,
51
+
threshold_size: @threshold_size,
52
+
increase_count: @increase_count,
53
+
increase_limit: @increase_limit,
52
54
}
53
55
end
54
56
@@ -60,65 +62,80 @@ def to_json(...)
60
62
# @attribute [Integer] The process ID to monitor.
61
63
attr:process_id
62
64
63
-
# @attribute [Numeric] The current maximum heap size.
64
-
attr:maximum
65
+
# @attribute [Numeric] The maximum process size observed.
66
+
attr_accessor:maximum_size
65
67
66
-
# @attribute [Numeric] The threshold for heap size increases.
67
-
attr:threshold
68
+
# @attribute [Numeric | Nil] The maximum process size allowed, before we assume a memory leak.
69
+
attr_accessor:maximum_size_limit
68
70
69
-
# @attribute [Numeric] The limit for the number of heap size increases, before we assume a memory leak.
70
-
attr:limit
71
+
# @attribute [Numeric] The threshold_size for process size increases.
72
+
attr_accessor:threshold_size
71
73
72
-
# @attribute [Integer] The number of increasing heap size samples.
73
-
attr:count
74
+
# @attribute [Integer] The number of increasing process size samples.
75
+
attr_accessor:increase_count
74
76
75
-
# The current resident set size (RSS) of the process.
76
-
#
77
-
# Even thought the absolute value of this number may not very useful, the relative change is useful for detecting memory leaks, and it works on most platforms.
0 commit comments