-
Notifications
You must be signed in to change notification settings - Fork 174
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
Reuse protobuf buffer to decrease memory use. #234
Conversation
Gerald Rule: Copy Observability on Veneur and Unilog pull requestscc @stripe/observability |
parser_test.go
Outdated
@@ -414,3 +414,14 @@ func TestServiceCheckMessageUnescape(t *testing.T) { | |||
assert.NoError(t, err, "Should have parsed correctly") | |||
assert.Equal(t, "foo\nbar\nbaz\n", svcheck.Message, "Should contain newline") | |||
} | |||
|
|||
func BenchmarkParseSSF(b *testing.B) { |
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.
Hooray for adding a benchmark function!
samplers/parser.go
Outdated
@@ -43,6 +43,9 @@ type MetricKey struct { | |||
JoinedTags string `json:"tagstring"` // tags in deterministic order, joined with commas | |||
} | |||
|
|||
// A reusable protobuf buffer, is not safe to use concurrently! |
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.
nit: it's not exported, but can we stick to godoc style for comments? (That is: // scratchBuff is a reusable protobuf buffer. It is not safe to share between goroutines
).
Yeah, let's definitely add a test for multiple calls to |
Added! |
lgtm! |
samplers/parser.go
Outdated
@@ -84,7 +89,10 @@ func ValidMetric(sample *UDPMetric) bool { | |||
// It also validates packets before returning them. |
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.
Add a note that this function isn't safe to use concurrently?
db7c153
to
6180799
Compare
re-approving for rebase |
6180799
to
f5b8bdf
Compare
Summary
Use a reusable buffer for unmarshaling spans.
Motivation
When inspecting the heap of a box with lots of spans, we noticed a lot of memory usage in decoding protobuf:
I did some digging and found that
proto.Buffer
can be reused. I wrote a benchmark that — with-benchmem
turned on — yields this:Without buffer reuse:
BenchmarkParseSSF-8 3000000 507 ns/op 384 B/op 3 allocs/op
With buffer reuse:
BenchmarkParseSSF-8 3000000 420 ns/op 176 B/op 2 allocs/op
Test plan
Existing tests? Maybe add one that verifies two subsequent calls to
ParseSSF
don't screw anything up?Rollout/monitoring/revert plan
Test out in QA
r? @aditya-stripe