Skip to content

sql: use stmt's span for exec stats propagation#61532

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:use-stmt-span
Mar 9, 2021
Merged

sql: use stmt's span for exec stats propagation#61532
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:use-stmt-span

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

Previously, when sampling the statement, we would always create a new
tracing span. However, there is another span that we can use instead:
we always create a tracing span for each statement in
connExecutor.execCmd. That span is not used directly for anything and
is needed because the transactions expect that a span is present in
their context. This commit utilizes the present tracing span for the
sampling purposes which gives us a performance boost (some benchmarks
show that this eliminates about a quarter of the performance overhead
with "always on" sampling").

Addresses: #59379.

Release justification: low-risk update to new functionality.

Release note: None

@yuzefovich yuzefovich requested review from a team, RaduBerinde and asubiotto March 5, 2021 06:39
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RaduBerinde and @yuzefovich)


pkg/sql/instrumentation.go, line 169 at r1 (raw file):

	ih.savePlanForStats = appStats.shouldSaveLogicalPlanDescription(fingerprint, implicitTxn)

	if sp := tracing.SpanFromContext(ctx); sp == nil {

Should we make this a util.CrdbTestBuild assertion instead? I'm not comfortable introducing this panic.

Copy link
Copy Markdown
Member Author

@yuzefovich yuzefovich 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 @asubiotto and @RaduBerinde)


pkg/sql/instrumentation.go, line 169 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

Should we make this a util.CrdbTestBuild assertion instead? I'm not comfortable introducing this panic.

Done.

Copy link
Copy Markdown
Contributor

@asubiotto asubiotto 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 @asubiotto, @RaduBerinde, and @yuzefovich)


pkg/sql/instrumentation.go, line 174 at r2 (raw file):

			panic(errors.AssertionFailedf("the context doesn't have a tracing span"))
		}
		return ctx, false

Sorry for being so nitpicky, but why are we returning early here? Granted that a nil span is unexpected, but it seems nicer to fallback to the code below. If we don't want to collect bundles etc... we'll return below, and if we do, we'll create our own span. If this is nil for some reason and a customer is trying to get a debug zip, it's going to be confusing and annoying when the bundle is empty.

Previously, when sampling the statement, we would always create a new
tracing span. However, there is another span that we can use instead:
we always create a tracing span for each statement in
`connExecutor.execCmd`. That span is not used directly for anything and
is needed because the transactions expect that a span is present in
their context. This commit utilizes the present tracing span for the
sampling purposes which gives us a performance boost (some benchmarks
show that this eliminates about a quarter of the performance overhead
with "always on" sampling").

Release justification: low-risk update to new functionality.

Release note: None
Copy link
Copy Markdown
Member Author

@yuzefovich yuzefovich 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 @asubiotto and @RaduBerinde)


pkg/sql/instrumentation.go, line 174 at r2 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

Sorry for being so nitpicky, but why are we returning early here? Granted that a nil span is unexpected, but it seems nicer to fallback to the code below. If we don't want to collect bundles etc... we'll return below, and if we do, we'll create our own span. If this is nil for some reason and a customer is trying to get a debug zip, it's going to be confusing and annoying when the bundle is empty.

Done. Simply "falling back" to the code below didn't work, and I didn't want to introduce some code path to handle a case that should never happen in the first place.

Copy link
Copy Markdown
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r3.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)

@yuzefovich
Copy link
Copy Markdown
Member Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 9, 2021

Build succeeded:

@craig craig bot merged commit b8e4c76 into cockroachdb:master Mar 9, 2021
@yuzefovich yuzefovich deleted the use-stmt-span branch March 9, 2021 23:04
irfansharif added a commit to irfansharif/cockroach that referenced this pull request Mar 11, 2021
This is a "by-hand" revert of 842d79b and motivates the next commit.

To reduce the memory overhead for tracing, statements will stop using
real spans unless absolutely required (for e.g. when SET TRACING = on).
The intent behind cockroachdb#61532 was to reduce the overhead of sampled
statements by not creating an additional new span when one was already
available (the statement's span). Well, with the next commit, the
statement's span will be a no-op one, so when we know that we're
sampling we'll want create a new span.

In the end, with respect to spans created, we'll be doing no worse for
sampled statements relative to cockroachdb#61532.

Release note: None
irfansharif added a commit to irfansharif/cockroach that referenced this pull request Mar 12, 2021
This is a "by-hand" revert of 842d79b and motivates the next commit.
The only "by-hand" bits comes from wanting to retain the comments
added in that commit.

To reduce the memory overhead for tracing, statements will stop using
real spans unless absolutely required (for e.g. when SET TRACING = on).
The intent behind cockroachdb#61532 was to reduce the overhead of sampled
statements by not creating an additional new span when one was already
available (the statement's span). Well, with the next commit, the
statement's span will be a no-op one, so when we know that we're
sampling we'll want create a new span.

In the end, with respect to spans created, we'll be doing no worse for
sampled statements relative to cockroachdb#61532.

Release note: None
irfansharif added a commit to irfansharif/cockroach that referenced this pull request Mar 13, 2021
This is a "by-hand" revert of 842d79b and motivates the next commit.
The only "by-hand" bits comes from wanting to retain the comments
added in that commit.

To reduce the memory overhead for tracing, statements will stop using
real spans unless absolutely required (for e.g. when SET TRACING = on).
The intent behind cockroachdb#61532 was to reduce the overhead of sampled
statements by not creating an additional new span when one was already
available (the statement's span). Well, with the next commit, the
statement's span will be a no-op one, so when we know that we're
sampling we'll want create a new span.

In the end, with respect to spans created, we'll be doing no worse for
sampled statements relative to cockroachdb#61532.

Release note: None
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.

3 participants