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

util/tracing: optimize span tags and expand their collection #70993

Merged
merged 1 commit into from
Oct 2, 2021

Conversation

andreimatei
Copy link
Contributor

This patch makes the collection of span tags generally allocation-free
by storing the tags into memory pre-allocated in the span. In tandem
with a previous commit which moved away from a generic (interface{})
interface for Span.SetTag(), this makes span collection very cheap. As
such, this patch also re-enables the collection of tags for
non-verbose (but also not no-op) spans. The collecting of tags on
non-verbose spans was stopped in
eba03c4 because of these allocations,
as well as the allocations performed by the variadic WithTags option
for StartSpan(). I'm not re-introducing WithTags.

The motivation for this change is that I want to make broader use of the
open spans registry, and I want (non-verbose) spans in the registry to
have their tags available for inspection. I'm also planning of
introducing new tags for static info defining a span (e.g. the SQL query
for spans representing query execution).

Note that tags in non-verbose spans continue to not be included in
Recordings (and hence not serialized-deserialized over the network).
This was the case, and the patch does not change it.

I've run BenchmarkTracing and it shows no change.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@@ -520,6 +520,10 @@ func (t *Tracer) startSpanGeneric(
helper.crdbSpan.mu.operation = opName
helper.crdbSpan.mu.recording.logs = newSizeLimitedBuffer(maxLogBytesPerSpan)
helper.crdbSpan.mu.recording.structured = newSizeLimitedBuffer(maxStructuredBytesPerSpan)
helper.crdbSpan.mu.tags = helper.crdbSpan.mu.tagsAlloc[:0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this tagsAlloc guy sitting on crdbSpanMu, you could just have it as part of the helper struct above, right?

This patch makes the collection of span tags generally allocation-free
by storing the tags into memory pre-allocated in the span. In tandem
with a previous commit which moved away from a generic (interface{})
interface for Span.SetTag(), this makes span collection very cheap. As
such, this patch also re-enables the collection of tags for
non-verbose (but also not no-op) spans. The collecting of tags on
non-verbose spans was stopped in
eba03c4 because of these allocations,
as well as the allocations performed by the variadic WithTags option
for StartSpan(). I'm not re-introducing WithTags.

The motivation for this change is that I want to make broader use of the
open spans registry, and I want (non-verbose) spans in the registry to
have their tags available for inspection. I'm also planning of
introducing new tags for static info defining a span (e.g. the SQL query
for spans representing query execution).

Note that tags in non-verbose spans continue to not be included in
Recordings (and hence not serialized-deserialized over the network).
This was the case, and the patch does not change it.

I've run BenchmarkTracing and it shows no change.

Release note: None
Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15 and @irfansharif)


pkg/util/tracing/tracer.go, line 523 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

Instead of this tagsAlloc guy sitting on crdbSpanMu, you could just have it as part of the helper struct above, right?

Yeah. I had oscillated about where to put it since I'm not sure how it'll end up looking when I start pooling the spans, but yeah for now at least I've moved it like you said.

Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15 and @irfansharif)

@craig
Copy link
Contributor

craig bot commented Oct 2, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Oct 2, 2021

Build succeeded:

@craig craig bot merged commit 1fc4fc1 into cockroachdb:master Oct 2, 2021
@andreimatei andreimatei deleted the tracing.tags-always branch January 22, 2022 22:06
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

3 participants