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

internal/datastreams: Improve performance #2455

Merged
merged 4 commits into from Dec 21, 2023
Merged

Conversation

piochelepiotr
Copy link
Collaborator

@piochelepiotr piochelepiotr commented Dec 20, 2023

What does this PR do?

  1. Adds a cache for hash computation
  2. Removes input channels to the processor that were slowing it down at high throughput

Before:

pkg: gopkg.in/DataDog/dd-trace-go.v1/internal/datastreams
BenchmarkSetCheckpoint
BenchmarkSetCheckpoint-10    	 1464592	       843.1 ns/op
PASS

Now:

pkg: gopkg.in/DataDog/dd-trace-go.v1/internal/datastreams
BenchmarkSetCheckpoint
BenchmarkSetCheckpoint-10    	 3519512	       358.1 ns/op
PASS

Motivation

For high throughput apps (tens of thousands of messages per second on a single host), the overhead of the tracer was pretty high (6% on a high throughput test application).

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@pr-commenter
Copy link

pr-commenter bot commented Dec 20, 2023

Benchmarks

Benchmark execution time: 2023-12-20 16:14:17

Comparing candidate commit f4ec4d8 in PR branch piotr-wolski/improve-perf with baseline commit 4ae528b in branch main.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 40 metrics, 0 unstable metrics.

scenario:BenchmarkSingleSpanRetention/no-rules-24

  • 🟩 execution_time [-6.475µs; -5.272µs] or [-2.593%; -2.111%]

@piochelepiotr piochelepiotr marked this pull request as ready for review December 20, 2023 12:57
@piochelepiotr piochelepiotr requested a review from a team as a code owner December 20, 2023 12:57
@piochelepiotr piochelepiotr requested a review from a team December 20, 2023 12:57
Copy link

@gabe-ochoa gabe-ochoa left a comment

Choose a reason for hiding this comment

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

Needs the big fix from the other repo but Lgtm otherwise.

Comment on lines +23 to +41
var s strings.Builder
l := 0
for _, t := range edgeTags {
l += len(t)
}
l += 8
s.Grow(l)
for _, t := range edgeTags {
s.WriteString(t)
}
s.WriteByte(byte(parentHash))
s.WriteByte(byte(parentHash >> 8))
s.WriteByte(byte(parentHash >> 16))
s.WriteByte(byte(parentHash >> 24))
s.WriteByte(byte(parentHash >> 32))
s.WriteByte(byte(parentHash >> 40))
s.WriteByte(byte(parentHash >> 48))
s.WriteByte(byte(parentHash >> 56))
return s.String()

Choose a reason for hiding this comment

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

Maybe a small optimization but we could return early here if there are no edge tags.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤔 If there are no edgeTags, going through the two empty loops will be really quick (also, no edge tags should never happen if there are no bugs).

Copy link
Contributor

@ajgajg1134 ajgajg1134 left a comment

Choose a reason for hiding this comment

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

Overall looks good just a few small questions!

internal/datastreams/fast_queue.go Outdated Show resolved Hide resolved
internal/datastreams/fast_queue.go Show resolved Hide resolved
Copy link
Contributor

@ajgajg1134 ajgajg1134 left a comment

Choose a reason for hiding this comment

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

nice! Thanks!

@ajgajg1134 ajgajg1134 enabled auto-merge (squash) December 21, 2023 18:07
@ajgajg1134 ajgajg1134 merged commit 82f5b7e into main Dec 21, 2023
152 of 153 checks passed
@ajgajg1134 ajgajg1134 deleted the piotr-wolski/improve-perf branch December 21, 2023 18:15
felixge added a commit that referenced this pull request Feb 5, 2024
This adds a test for an issue that seems to have been introduced in:
#2455
@felixge
Copy link
Member

felixge commented Mar 5, 2024

Since somebody mentioned it to me on slack, let me clarify something here: My commit 803b0d4 that references this PR was a deadend. I briefly took a look at this code because it seemed suspicious, but it held up to my scrutiny and I believe it's working correctly 👏.

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.

None yet

4 participants