Commit 2e896ec
authored
memory_chunk: clear internal memory use in buffer string (#4845)
**Which issue(s) this PR fixes**:
Fixes #1657
**What this PR does / why we need it**:
Seems that a full GC have to run in order to collect the wasted String
object in `@chunk`.
However, full GC is not performed frequently.
This patch purges internal memory in wasted String object immediately.
Here is memory usage retrieved by `ObjectSpace.memsize_of_all`.

> [!NOTE]
> Ruby has various optimization, such as reusing freed heap areas by
pooling them.
> For this reason, it may not be reflected in the process's memory usage
immediately even if it clear the object.
## Reproduce
* Configuration
```
<source>
@type tcp
tag testing
format json
port 10130
</source>
<match **>
@type forward
require_ack_response true
<server>
host 127.0.0.1
port 10131
</server>
## Tune the buffer parameters
<buffer tag>
flush_mode interval
flush_interval 1s
</buffer>
</match>
```
* test data
```ruby
require "socket"
require "json"
i = 0
Thread.new do
s = TCPSocket.open("localhost", 10130)
data = {"message": "a" * 512 * 1024}
loop do
puts "[#{i}]"
data["number"] = i
s.puts data.to_json
i += 1
sleep 0.01
end
s.close
end
sleep 20
```
**Docs Changes**:
Not needed.
**Release Note**:
buf_memory: improve memory performance
---------
Signed-off-by: Shizuo Fujita <[email protected]>1 parent c182b6a commit 2e896ec
File tree
2 files changed
+4
-12
lines changed- lib/fluent/plugin/buffer
- test/plugin
2 files changed
+4
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 125 | + | |
130 | 126 | | |
131 | 127 | | |
132 | 128 | | |
| |||
160 | 156 | | |
161 | 157 | | |
162 | 158 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 159 | + | |
168 | 160 | | |
169 | 161 | | |
170 | 162 | | |
| |||
0 commit comments