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: add pprof labels based on the statement type #30930

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@jordanlewis
Member

jordanlewis commented Oct 3, 2018

pprof profiles will now be enhanced with the type of the statement that
caused the creation of each stack. statement types are things like
'SELECT', 'INSERT', 'ALTER TABLE', etc.

This example output is produced based on a kv95 workload:

(pprof) tags
 stmt: Total 27.7s
       25.4s (91.77%): SELECT
        2.3s ( 8.23%): INSERT

Release note: None

@jordanlewis jordanlewis requested review from cockroachdb/sql-execution-prs as code owners Oct 3, 2018

@cockroach-teamcity

This comment has been minimized.

Show comment
Hide comment
@cockroach-teamcity

cockroach-teamcity Oct 3, 2018

Member

This change is Reviewable

Member

cockroach-teamcity commented Oct 3, 2018

This change is Reviewable

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member

Here's a sample profile created with the new tags:

pprof.samples.cpu.007.pb.gz

Member

jordanlewis commented Oct 3, 2018

Here's a sample profile created with the new tags:

pprof.samples.cpu.007.pb.gz

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member

https://rakyll.org/profiler-labels/ has more details on how the labels work, btw.

Member

jordanlewis commented Oct 3, 2018

https://rakyll.org/profiler-labels/ has more details on how the labels work, btw.

@tschottdorf

This comment has been minimized.

Show comment
Hide comment
@tschottdorf

tschottdorf Oct 3, 2018

Member

Just a drive by question, what's the cost of a label? Are they cheap enough to throw in basically as we please?

Member

tschottdorf commented Oct 3, 2018

Just a drive by question, what's the cost of a label? Are they cheap enough to throw in basically as we please?

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member

They seem very cheap, but I don't know about using them more than on the order of once per query. They do a context.Value call and call a runtime function that sets a field on a pointer.

Member

jordanlewis commented Oct 3, 2018

They seem very cheap, but I don't know about using them more than on the order of once per query. They do a context.Value call and call a runtime function that sets a field on a pointer.

@nvanbenschoten

Same question as Tobi. This is really neat, but I'd like to experimentally confirm that the overhead is completely negligible before making the change.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/sql/conn_executor_exec.go, line 26 at r1 (raw file):

	"github.com/pkg/errors"

	pprof "runtime/pprof"

Weird import.

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member
Switching to pprof-labels~
+ make bench PKG=./pkg/bench BENCHTIMEOUT=5m 'BENCHES=BenchmarkSelect1/^Cockroach$$' 'TESTFLAGS=-count 10 -benchmem'
Switching to pprof-labels
+ make bench PKG=./pkg/bench BENCHTIMEOUT=5m 'BENCHES=BenchmarkSelect1/^Cockroach$$' 'TESTFLAGS=-count 10 -benchmem'
name                 old time/op    new time/op    delta
Select1/Cockroach-8     126µs ± 1%     140µs ±13%  +10.74%  (p=0.000 n=9+9)

name                 old alloc/op   new alloc/op   delta
Select1/Cockroach-8    18.8kB ± 0%    19.2kB ± 0%   +2.22%  (p=0.000 n=7+9)

name                 old allocs/op  new allocs/op  delta
Select1/Cockroach-8       164 ± 0%       169 ± 0%   +3.05%  (p=0.000 n=10+10)

Pretty disappointing. Not sure this is worth it. Though the Do call is high level and always allocates something - let me see if I can improve the performance by doing things with lower level calls.

Member

jordanlewis commented Oct 3, 2018

Switching to pprof-labels~
+ make bench PKG=./pkg/bench BENCHTIMEOUT=5m 'BENCHES=BenchmarkSelect1/^Cockroach$$' 'TESTFLAGS=-count 10 -benchmem'
Switching to pprof-labels
+ make bench PKG=./pkg/bench BENCHTIMEOUT=5m 'BENCHES=BenchmarkSelect1/^Cockroach$$' 'TESTFLAGS=-count 10 -benchmem'
name                 old time/op    new time/op    delta
Select1/Cockroach-8     126µs ± 1%     140µs ±13%  +10.74%  (p=0.000 n=9+9)

name                 old alloc/op   new alloc/op   delta
Select1/Cockroach-8    18.8kB ± 0%    19.2kB ± 0%   +2.22%  (p=0.000 n=7+9)

name                 old allocs/op  new allocs/op  delta
Select1/Cockroach-8       164 ± 0%       169 ± 0%   +3.05%  (p=0.000 n=10+10)

Pretty disappointing. Not sure this is worth it. Though the Do call is high level and always allocates something - let me see if I can improve the performance by doing things with lower level calls.

sql: add pprof labels based on the statement type
pprof profiles will now be enhanced with the type of the statement that
caused the creation of each stack. statement types are things like
'SELECT', 'INSERT', 'ALTER TABLE', etc.

Release note: None
@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member

Replacing the Do call makes this seem ok again.

name                 old time/op    new time/op    delta
Select1/Cockroach-8     126µs ± 2%     127µs ± 0%    ~     (p=0.156 n=10+9)

name                 old alloc/op   new alloc/op   delta
Select1/Cockroach-8    18.8kB ± 0%    19.2kB ± 0%  +2.26%  (p=0.000 n=10+10)

name                 old allocs/op  new allocs/op  delta
Select1/Cockroach-8       164 ± 0%       169 ± 0%  +3.05%  (p=0.000 n=10+10)
Member

jordanlewis commented Oct 3, 2018

Replacing the Do call makes this seem ok again.

name                 old time/op    new time/op    delta
Select1/Cockroach-8     126µs ± 2%     127µs ± 0%    ~     (p=0.156 n=10+9)

name                 old alloc/op   new alloc/op   delta
Select1/Cockroach-8    18.8kB ± 0%    19.2kB ± 0%  +2.26%  (p=0.000 n=10+10)

name                 old allocs/op  new allocs/op  delta
Select1/Cockroach-8       164 ± 0%       169 ± 0%  +3.05%  (p=0.000 n=10+10)
@nvanbenschoten

This comment has been minimized.

Show comment
Hide comment
@nvanbenschoten

nvanbenschoten Oct 3, 2018

Member

Can we statically allocate the labels for all statement types to avoid the increase in memory usage?

Member

nvanbenschoten commented Oct 3, 2018

Can we statically allocate the labels for all statement types to avoid the increase in memory usage?

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member

We'll still have to allocate a map in WithLabels, since the labelContextKey isn't exported for us to muck with, but I think you're right that we can avoid making LabelSets over and over. Good suggestion.

Member

jordanlewis commented Oct 3, 2018

We'll still have to allocate a map in WithLabels, since the labelContextKey isn't exported for us to muck with, but I think you're right that we can avoid making LabelSets over and over. Good suggestion.

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 3, 2018

Member

Nevermind, there's no way we can reduce allocations here. However, I think the increase of allocations is negligible. The query benchmarked here is a worst-case - it's SELECT 1 which does almost no work at all. Normal queries do a lot more. Thoughts?

Member

jordanlewis commented Oct 3, 2018

Nevermind, there's no way we can reduce allocations here. However, I think the increase of allocations is negligible. The query benchmarked here is a worst-case - it's SELECT 1 which does almost no work at all. Normal queries do a lot more. Thoughts?

@nvanbenschoten

This comment has been minimized.

Show comment
Hide comment
@nvanbenschoten

nvanbenschoten Oct 4, 2018

Member

Nevermind, there's no way we can reduce allocations here.

Can't we at least avoid the pprof.Labels allocation?

Member

nvanbenschoten commented Oct 4, 2018

Nevermind, there's no way we can reduce allocations here.

Can't we at least avoid the pprof.Labels allocation?

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 4, 2018

Member

That doesn't get allocated.

Member

jordanlewis commented Oct 4, 2018

That doesn't get allocated.

@nvanbenschoten

This comment has been minimized.

Show comment
Hide comment
@nvanbenschoten

nvanbenschoten Oct 4, 2018

Member

Really? Aren't there varargs and a slice in pprof.Labels?

Member

nvanbenschoten commented Oct 4, 2018

Really? Aren't there varargs and a slice in pprof.Labels?

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 5, 2018

Member

I ran this change through pprof and didn't see any allocations on those lines. Maybe I did something wrong?

Member

jordanlewis commented Oct 5, 2018

I ran this change through pprof and didn't see any allocations on those lines. Maybe I did something wrong?

@nvanbenschoten

Code LGTM, so up to you whether you think the added debuggability from this change is worth the minor increase in allocations.

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 11, 2018

Member

I'm not really sure. I'm going to let this sit a while longer and revisit when I have more headspace for it. Thanks for the reviews so far.

Member

jordanlewis commented Oct 11, 2018

I'm not really sure. I'm going to let this sit a while longer and revisit when I have more headspace for it. Thanks for the reviews so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment