-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Reduce memory allocations in decode_cef processor #16587
Merged
andrewkroh
merged 5 commits into
elastic:master
from
andrewkroh:feature/libbeat/decode-cef-perf
Feb 26, 2020
Merged
Reduce memory allocations in decode_cef processor #16587
andrewkroh
merged 5 commits into
elastic:master
from
andrewkroh:feature/libbeat/decode-cef-perf
Feb 26, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Change the input of the cef parser to accept a string instead of []byte to avoid unnecessary copies. Data is still copied from the input message when it contains escape sequences. Another minor improvement is to allocate the map for the CEF extensions up front based on the estimated number of extension fields. Results from `go test -run none -bench . -benchtime 5s -benchmem .` before and after: $ benchcmp before.txt after.txt benchmark old ns/op new ns/op delta BenchmarkProcessorRun/short_msg-12 4833 4684 -3.08% BenchmarkProcessorRun/long_msg-12 55724 52493 -5.80% benchmark old allocs new allocs delta BenchmarkProcessorRun/short_msg-12 55 41 -25.45% BenchmarkProcessorRun/long_msg-12 349 219 -37.25% benchmark old bytes new bytes delta BenchmarkProcessorRun/short_msg-12 3728 3424 -8.15% BenchmarkProcessorRun/long_msg-12 26929 21173 -21.37%
andrewkroh
force-pushed
the
feature/libbeat/decode-cef-perf
branch
from
February 26, 2020 02:26
30e4324
to
6f62fff
Compare
adriansr
approved these changes
Feb 26, 2020
andrewkroh
added
the
needs_backport
PR is waiting to be backported to other branches.
label
Feb 26, 2020
andrewkroh
added a commit
to andrewkroh/beats
that referenced
this pull request
Mar 11, 2020
* Add decode_cef processor benchmarks * Take advantage of string slicing to avoid allocations Change the input of the cef parser to accept a string instead of []byte to avoid unnecessary copies. Data is still copied from the input message when it contains escape sequences. Another minor improvement is to allocate the map for the CEF extensions up front based on the estimated number of extension fields. Results from `go test -run none -bench . -benchtime 5s -benchmem .` before and after: $ benchcmp before.txt after.txt benchmark old ns/op new ns/op delta BenchmarkProcessorRun/short_msg-12 4833 4684 -3.08% BenchmarkProcessorRun/long_msg-12 55724 52493 -5.80% benchmark old allocs new allocs delta BenchmarkProcessorRun/short_msg-12 55 41 -25.45% BenchmarkProcessorRun/long_msg-12 349 219 -37.25% benchmark old bytes new bytes delta BenchmarkProcessorRun/short_msg-12 3728 3424 -8.15% BenchmarkProcessorRun/long_msg-12 26929 21173 -21.37% (cherry picked from commit 7e7bc2e)
5 tasks
andrewkroh
added
v7.7.0
and removed
needs_backport
PR is waiting to be backported to other branches.
labels
Mar 11, 2020
andrewkroh
added a commit
that referenced
this pull request
Mar 11, 2020
* Add decode_cef processor benchmarks * Take advantage of string slicing to avoid allocations Change the input of the cef parser to accept a string instead of []byte to avoid unnecessary copies. Data is still copied from the input message when it contains escape sequences. Another minor improvement is to allocate the map for the CEF extensions up front based on the estimated number of extension fields. Results from `go test -run none -bench . -benchtime 5s -benchmem .` before and after: $ benchcmp before.txt after.txt benchmark old ns/op new ns/op delta BenchmarkProcessorRun/short_msg-12 4833 4684 -3.08% BenchmarkProcessorRun/long_msg-12 55724 52493 -5.80% benchmark old allocs new allocs delta BenchmarkProcessorRun/short_msg-12 55 41 -25.45% BenchmarkProcessorRun/long_msg-12 349 219 -37.25% benchmark old bytes new bytes delta BenchmarkProcessorRun/short_msg-12 3728 3424 -8.15% BenchmarkProcessorRun/long_msg-12 26929 21173 -21.37% (cherry picked from commit 7e7bc2e)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Change the input parameter of the cef parser to accept a
string
instead of[]byte
to avoid unnecessary copies. Data is still copied from the input message when it contains escape sequences, but otherwise a slice of the original message is used.Another minor improvement is to allocate the map for the CEF extensions up front based on the
estimated number of extension fields.
Results from
go test -run none -bench . -benchtime 5s -benchmem .
before and after:(On my Macbook Intel Core i9 2.9 GHz, that's 213.4K EPS for short messages and 19.0K EPS for long messages.)
Why is it important?
For short CEF messages the processor is fast, but with longer messages with lots of extensions it starts to slow down.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration files