-
Notifications
You must be signed in to change notification settings - Fork 905
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
Rules matching perf improvements #2210
Conversation
80ef37f
to
19483c1
Compare
19483c1
to
879b8d4
Compare
userspace/engine/falco_engine.cpp
Outdated
return add_source(source, filter_factory, formatter_factory, ruleset_factory); | ||
size_t idx = add_source(source, filter_factory, formatter_factory, ruleset_factory); | ||
|
||
if(source == "syscall") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(source == "syscall") | |
if(source == falco_common::syscall_source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes! Fixed.
When doing some testing of falco on very high event volumes (> 1.5M events/second), I found that the time taken to look up a falco_source struct had a non-negligible contribution to cpu usage. So instead of looking up the source from the source_idx every time, separately save the source for syscalls in the falco_engine object directly. The separately saved copy is only used once someone calls add_source with source="syscall". Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
Instead of using a falco_rule struct on the stack, use a single value inside the falco_source struct. It's mutable as find_source returns a const struct. At very high event volumes (> 1M syscalls/second), even the tiny time it takes to create/destroy the struct starts to add up, and this switch has some small cpu savings. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
879b8d4
to
a00443b
Compare
/milestone 0.33.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: d7a242fdecda509ac2de5656b94629c0855d5388
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jasondellaluce, leogr, mstemm The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The optimization in #2210 had a bug when the engine uses multiple sources at the same time--m_syscall_source is a pointer to an entry in the indexed vector m_sources, but if add_source is called multiple times, the vector is resized, which copies the structs but invalidates any pointer to the vector entries. So instead of caching m_syscall_source in add_source(), cache it in process_events(). m_sources won't change once processing events starts. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
The optimization in #2210 had a bug when the engine uses multiple sources at the same time--m_syscall_source is a pointer to an entry in the indexed vector m_sources, but if add_source is called multiple times, the vector is resized, which copies the structs but invalidates any pointer to the vector entries. So instead of caching m_syscall_source in add_source(), cache it in process_events(). m_sources won't change once processing events starts. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
The optimization in falcosecurity#2210 had a bug when the engine uses multiple sources at the same time--m_syscall_source is a pointer to an entry in the indexed vector m_sources, but if add_source is called multiple times, the vector is resized, which copies the structs but invalidates any pointer to the vector entries. So instead of caching m_syscall_source in add_source(), cache it in process_events(). m_sources won't change once processing events starts. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area engine
What this PR does / why we need it:
Some small changes to rules matching that reduce cpu usage with high event volumes (> 1M syscalls/sec)
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: