Skip to content

[networks] Improve memory allocation pattern #9206

Merged
p-lambert merged 11 commits intomainfrom
pedro/tracer-mem-improvements
Sep 22, 2021
Merged

[networks] Improve memory allocation pattern #9206
p-lambert merged 11 commits intomainfrom
pedro/tracer-mem-improvements

Conversation

@p-lambert
Copy link
Copy Markdown
Member

@p-lambert p-lambert commented Sep 21, 2021

What does this PR do?

This PR refactors some parts of the network-tracer to reduce the number and the bursty pattern of allocations.
In our load test server I witnessed a ~30% drop in bytes allocated/s and a ~20% CPU drop

bytes allocated/s
Screen Shot 2021-09-21 at 1 14 47 PM

CPU cores
Screen Shot 2021-09-21 at 1 14 25 PM

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Describe how to test your changes

I'm only changing implementation details and everything should be covered by tests already.

Checklist

  • A release note has been added or the changelog/no-changelog label has been applied.
  • The need-change/operator and need-change/helm labels has been applied if applicable.
  • The appropriate team/.. label has been applied, if known.
  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • The config template has been updated if applicable.

Note: Adding GitHub labels is only possible for contributors with write access.

Comment thread pkg/network/buffer.go Outdated
Comment thread pkg/network/buffer.go Outdated
Comment thread pkg/network/tracer/connection/kprobe/tracer.go Outdated
Comment thread pkg/network/tracer/tracer_test.go
Comment thread pkg/network/buffer.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not something for this PR, but I'd be curious if we get any perf gains from getting rid of the PerfHandler (and thus the channel) and using the callback directly. We might need to think about any thread safety concerns, but I know channels can be heavy-handed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. I was also wondering if we could write our own perf poller or add an alternative implementation to the ebpf library that uses a buffer pool, because a large chunk of the memory allocations now come from it.

@p-lambert p-lambert force-pushed the pedro/tracer-mem-improvements branch from 4f4fc54 to 77971fa Compare September 21, 2021 19:22
@p-lambert p-lambert marked this pull request as ready for review September 21, 2021 19:24
@p-lambert p-lambert requested a review from a team as a code owner September 21, 2021 19:24
@p-lambert p-lambert added this to the 7.32.0 milestone Sep 21, 2021
}
err = ebpfTracer.Start(tr.closedCB)
if err != nil {
return nil, fmt.Errorf("could not start ebpf manager: %s", err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to tear anything down at this point, since the tracer object has been created along with possible HTTP and DNS features? I think this is why it was before object creation before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Great catch. I added some changes to handle that scenario

Copy link
Copy Markdown
Member

@brycekahle brycekahle left a comment

Choose a reason for hiding this comment

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

One comment, but otherwise looks good.

@p-lambert p-lambert merged commit eaf8fe6 into main Sep 22, 2021
@p-lambert p-lambert deleted the pedro/tracer-mem-improvements branch September 22, 2021 17:07
zandrewitte pushed a commit to StackVista/stackstate-agent that referenced this pull request Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants