Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reuse inner packforward payload unpacker #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.4.3
- Fix: reduce overhead of unpacking packforward-payloads by reusing a single instance [#32](https://github.com/logstash-plugins/logstash-codec-fluent/pull/32)

## 3.4.2
- Fix: Convert LogStash::Timestamp values to iso-8601 to resolve crash issue with `msgpack` serialization [#30](https://github.com/logstash-plugins/logstash-codec-fluent/pull/30)

Expand Down
3 changes: 2 additions & 1 deletion lib/logstash/codecs/fluent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def register
end
@packer = @factory.packer
@decoder = @factory.unpacker
@packforward_decoder = nil
end

def decode(data, &block)
Expand Down Expand Up @@ -116,7 +117,7 @@ def decode_event(data, &block)
raise(LogStash::Error, "PackedForward with compression is not supported")
end

entries_decoder = @factory.unpacker
entries_decoder = (@packforward_decoder ||= @factory.unpacker).tap(&:reset)
Copy link

Choose a reason for hiding this comment

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

As I understand decode, when used by a input like TCP (which is multithreaded), is used by multiple threads, so I have feeling that @packforward_decoder.reset could be called and used by multiple threads.
WDYT?

Copy link
Contributor Author

@yaauie yaauie Jun 25, 2024

Choose a reason for hiding this comment

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

TCP clones the codec (as do other inputs), and gives a fresh codec to each connection, so this should never be shared.

entries_decoder.feed_each(entries) do |entry|
yield generate_event(entry[1], entry[0], tag)
end
Expand Down
2 changes: 1 addition & 1 deletion logstash-codec-fluent.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-codec-fluent'
s.version = '3.4.2'
s.version = '3.4.3'
s.licenses = ['Apache License (2.0)']
s.summary = "Reads the `fluentd` `msgpack` schema"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down