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

sql: do not consider TCL stmts in sql stats tracing #138041

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

xinhaoz
Copy link
Member

@xinhaoz xinhaoz commented Dec 27, 2024

For SQL stats we trace every new fingerprint in an application
container in order to populate statistics that are only available
via tracing for each fingerprint. This sampling logic worked by
tracking the SQL fingerprint strings encountered by each application
but did not factor in fingerprints that are not tracked by SQL stats,
such as TCL statements (BEGIN, COMMIT, ROLLBACK), were being treated
as new fingerprints on each execution which resulted in tracing being
turned on. This commit ensures that we don't consider TCL statements
in this sampling strategy. TestSampledStatsCollectionOnNewFingerprint
is also fixed as it was assuming that previously seen statements in
new transactions would trigger this sampling behaviour when it should
not - this was being erronneously triggered by BEGIN.

name                                   old time/op    new time/op    delta
Sysbench/SQL/3node/oltp_read_write-10    5.61ms ± 3%    5.69ms ± 4%    ~     (p=0.167 n=8+9)

name                                   old alloc/op   new alloc/op   delta
Sysbench/SQL/3node/oltp_read_write-10    2.15MB ± 2%    2.12MB ± 2%  -1.24%  (p=0.029 n=10+10)

name                                   old allocs/op  new allocs/op  delta
Sysbench/SQL/3node/oltp_read_write-10     10.7k ± 1%     10.5k ± 0%  -1.69%  (p=0.000 n=10+9)

Epic: none
Part of: #133307

Release note: None

Copy link

blathers-crl bot commented Dec 27, 2024

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@xinhaoz xinhaoz force-pushed the disable-sampling-tcl branch 4 times, most recently from 443406e to 6da47a8 Compare December 30, 2024 16:34
@xinhaoz xinhaoz marked this pull request as ready for review December 30, 2024 16:35
@xinhaoz xinhaoz requested review from a team and kyle-a-wong and removed request for a team December 30, 2024 17:35
Copy link
Contributor

@kyle-a-wong kyle-a-wong left a comment

Choose a reason for hiding this comment

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

Nice! LGTM

@@ -251,10 +252,11 @@ func TestSampledStatsCollectionOnNewFingerprint(t *testing.T) {

require.Equal(t, len(queries), len(collectedTxnStats))

// We should have collected stats for each of the queries.
for i := range collectedTxnStats {
// We should have collected stats for each of the first 4 queries.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe change this to "each of the queries, except the last" or something, since more queries could be added in the future

@dhartunian dhartunian added the o-perf-efficiency Related to performance efficiency label Jan 6, 2025
For SQL stats we trace every new fingerprint in an application
container in order to populate statistics that are only available
via tracing for each fingerprint. This sampling logic worked by
tracking the SQL fingerprint strings encountered by each application
but did not factor in fingerprints that are not tracked by SQL stats,
such as TCL statements (BEGIN, COMMIT, ROLLBACK), were being treated
as new fingerprints on each execution which resulted in tracing being
turned on. This commit ensures that we don't consider TCL statements
in this sampling strategy. TestSampledStatsCollectionOnNewFingerprint
is also fixed as it was assuming that previously seen statements in
new transactions would trigger this sampling behaviour when it should
not - this was being erronneously triggered by `BEGIN`.

```
name                                   old time/op    new time/op    delta
Sysbench/SQL/3node/oltp_read_write-10    5.61ms ± 3%    5.69ms ± 4%    ~     (p=0.167 n=8+9)

name                                   old alloc/op   new alloc/op   delta
Sysbench/SQL/3node/oltp_read_write-10    2.15MB ± 2%    2.12MB ± 2%  -1.24%  (p=0.029 n=10+10)

name                                   old allocs/op  new allocs/op  delta
Sysbench/SQL/3node/oltp_read_write-10     10.7k ± 1%     10.5k ± 0%  -1.69%  (p=0.000 n=10+9)
```

Epic: none
Part of: cockroachdb#133307

Release note: None
@xinhaoz xinhaoz force-pushed the disable-sampling-tcl branch from 6da47a8 to 8f86503 Compare January 6, 2025 15:33
@xinhaoz
Copy link
Member Author

xinhaoz commented Jan 6, 2025

TFTR!
bors r+

@craig craig bot merged commit f744ccb into cockroachdb:master Jan 6, 2025
22 checks passed
@tbg
Copy link
Member

tbg commented Jan 7, 2025

Nice, thank you!

@xinhaoz xinhaoz deleted the disable-sampling-tcl branch January 8, 2025 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
o-perf-efficiency Related to performance efficiency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants