Skip to content

Commit 7704d75

Browse files
authored
formatter_json: reduce memory usage (#4886)
**Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: When dealing with long logs at fast, it might improve memory efficient to clear the original strings used in string interpolation. This is similar with #4884 . ![chart](https://github.com/user-attachments/assets/2a179770-a99f-45c0-bf60-797c567e9505) * config ``` <source> @type sample tag test sample {"message": "#{'a' * 100 * 1024}"} size 100 </source> <match **> @type file path "#{File.expand_path '~/tmp/log'}" format json </match> ``` **Docs Changes**: **Release Note**: Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent dfa1b26 commit 7704d75

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/fluent/plugin/formatter_json.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def configure(conf)
4848
end
4949

5050
def format(tag, time, record)
51-
"#{@dump_proc.call(record)}#{@newline}"
51+
json_str = @dump_proc.call(record)
52+
"#{json_str}#{@newline}"
53+
ensure
54+
json_str&.clear
5255
end
5356

5457
def format_without_nl(tag, time, record)

0 commit comments

Comments
 (0)