Skip to content

Conversation

Watson1978
Copy link
Contributor

@Watson1978 Watson1978 commented Jan 9, 2025

Which issue(s) this PR fixes:
Fixes #

What this PR does / why we need it:
When log files are rotated at high speed, the lifespan of IOHandler objects may become extended.
Along with this, the lifespan of @iobuf also increases.

Since @iobuf uses 8 KB of memory, if many such objects exist simultaneously, memory usage might significantly increase.

Docs Changes:

Release Note:

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978 Watson1978 changed the title in_tail: reduce the survival time of the buffer area in_tail: reduce the lifespan of the buffer area Jan 9, 2025
@Watson1978 Watson1978 marked this pull request as ready for review January 9, 2025 05:32
@Watson1978 Watson1978 requested a review from daipom January 9, 2025 05:36
@daipom daipom added this to the v1.19.0 milestone Jan 9, 2025
Copy link
Contributor

@daipom daipom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@daipom daipom merged commit 17d9322 into fluent:master Jan 9, 2025
13 checks passed
@Watson1978 Watson1978 deleted the iobuf branch January 10, 2025 00:35
daipom pushed a commit that referenced this pull request Mar 26, 2025
**Which issue(s) this PR fixes**: 
Fixes #

**What this PR does / why we need it**: 
Previous, I changed lifespan of `iobuf` at
#4763 to work GC collector well.

In addition, it seems that clearing `iobuf` manually when it is no
longer needed, it might improve memory efficiency.


![memory_usage](https://github.com/user-attachments/assets/2ed3afeb-edd6-4f9f-ab6f-1bb602390f25)

* config
```
<source>
  @type tail
  path "#{File.expand_path '~/tmp/access*.log'}"
  pos_file "#{File.expand_path '~/tmp/fluentd/access.log.pos'}"
  tag log
  refresh_interval 5s
  <parse>
    @type none
  </parse>
</source>

<match **>
  @type file
  path "#{File.expand_path '~/tmp/log'}"
</match>
```

* script to generate log data
```
require "json"

path = File.expand_path("~/tmp/access.log")

File.open(path, "w") do |f|
  loop do
    log = { time: Time.now, message: "a" * 10_000 }.to_json
    f.puts log
    sleep 0.05
  end
end
```

Related to #4808

**Docs Changes**:

**Release Note**:

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants