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

fix(godeltaprof): fix mutex tests on gotip #108

Merged
merged 33 commits into from
Jun 4, 2024

Conversation

korniltsev
Copy link
Collaborator

@korniltsev korniltsev commented May 22, 2024

Fixes #103

This PR fixes an issue when a heap/mutex profile has a record with equal stack (by accumulating values for duplicate stacks before delta computation).
The issue was found in tests for mutex(golang started to produce two profile records for the same mutex ( see the linked issue for more info))
I'm not sure if it is possible to trigger the issue for heap.

The PR turned up big because of refactored test helpers for reuse. I can split PR into 2 or 3 smaller ones if needed.

This PR also drops support for go16, go17 as I wanted to use generics in prof/map.go

goos: darwin
goarch: arm64
pkg: github.com/grafana/pyroscope-go/godeltaprof/compat
                                      │   old.txt   │               new.txt                │
                                      │   sec/op    │    sec/op      vs base               │
HeapCompression-8                       691.1µ ± 0%    729.8µ ± 65%   +5.59% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   640.6µ ± 1%    693.8µ ±  9%   +8.30% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   643.2µ ± 1%    690.3µ ±  1%   +7.33% (p=0.002 n=6)
HeapDelta-8                             76.26µ ± 1%   113.92µ ±  2%  +49.38% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8         48.98µ ± 1%    81.11µ ±  2%  +65.59% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8         49.03µ ± 1%    81.14µ ±  1%  +65.49% (p=0.002 n=6)
geomean                                 193.3µ         253.0µ        +30.87%

                                      │   old.txt    │               new.txt               │
                                      │     B/op     │     B/op      vs base               │
HeapCompression-8                       974.1Ki ± 0%   973.9Ki ± 0%   -0.03% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   974.6Ki ± 0%   974.3Ki ± 0%   -0.02% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   974.6Ki ± 0%   974.3Ki ± 0%   -0.03% (p=0.002 n=6)
HeapDelta-8                              333.00 ± 0%     53.00 ± 0%  -84.08% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8          312.00 ± 0%     30.00 ± 0%  -90.38% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8          312.00 ± 0%     30.00 ± 0%  -90.38% (p=0.002 n=6)
geomean                                 17.42Ki        5.874Ki       -66.28%

                                      │  old.txt   │              new.txt              │
                                      │ allocs/op  │ allocs/op   vs base               │
HeapCompression-8                       788.0 ± 0%   787.0 ± 0%   -0.13% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   788.0 ± 0%   787.0 ± 0%   -0.13% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   788.0 ± 0%   787.0 ± 0%   -0.13% (p=0.002 n=6)
HeapDelta-8                             2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
geomean                                 39.70        28.05       -29.33%

So it looks like the cost of deduplication is about 5% of overall time(including compression), which is not that bad.

@korniltsev
Copy link
Collaborator Author

yey, green light \M/

@korniltsev korniltsev force-pushed the korniltsev/gotip-fix-mutex-tests branch from 6c4afd9 to 5c31860 Compare May 23, 2024 08:06
@korniltsev korniltsev force-pushed the korniltsev/gotip-fix-mutex-tests branch from 5c31860 to 65a479d Compare May 24, 2024 06:08
@korniltsev korniltsev marked this pull request as ready for review May 24, 2024 17:25
@korniltsev korniltsev requested a review from a team as a code owner May 24, 2024 17:25
@korniltsev
Copy link
Collaborator Author

goos: darwin
goarch: arm64
pkg: github.com/grafana/pyroscope-go/godeltaprof/compat
                                      │   old.txt   │              new.txt               │
                                      │   sec/op    │   sec/op     vs base               │
HeapCompression-8                       715.6µ ± 1%   570.0µ ± 1%  -20.35% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   676.0µ ± 0%   544.5µ ± 1%  -19.45% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   681.8µ ± 1%   543.8µ ± 1%  -20.25% (p=0.002 n=6)
HeapDelta-8                             78.44µ ± 1%   97.20µ ± 2%  +23.92% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8         54.43µ ± 1%   80.91µ ± 1%  +48.65% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8         54.02µ ± 1%   81.12µ ± 2%  +50.16% (p=0.002 n=6)
geomean                                 205.8µ        218.1µ        +5.96%

                                      │   old.txt    │               new.txt               │
                                      │     B/op     │     B/op      vs base               │
HeapCompression-8                       965.7Ki ± 0%   969.5Ki ± 0%   +0.39% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   965.7Ki ± 0%   969.1Ki ± 0%   +0.35% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   965.6Ki ± 0%   969.1Ki ± 0%   +0.36% (p=0.002 n=6)
HeapDelta-8                              333.00 ± 0%     50.00 ± 2%  -84.98% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8          313.00 ± 0%     30.00 ± 0%  -90.42% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8          313.00 ± 0%     30.00 ± 0%  -90.42% (p=0.002 n=6)
geomean                                 17.36Ki        5.802Ki       -66.57%

                                      │  old.txt   │              new.txt              │
                                      │ allocs/op  │ allocs/op   vs base               │
HeapCompression-8                       788.0 ± 0%   782.0 ± 0%   -0.76% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   788.0 ± 0%   782.0 ± 0%   -0.76% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   788.0 ± 0%   782.0 ± 0%   -0.76% (p=0.002 n=6)
HeapDelta-8                             2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
geomean                                 39.70        27.96       -29.56%

The delta bench became slower by 20-50%
What I don't understand is why compression test became faster 20% 🤷

@korniltsev
Copy link
Collaborator Author

korniltsev commented May 28, 2024

What I don't understand is why compression test became faster 20% 🤷

Ok, I understand now: the benchmarks were using different randomized testdata. Fixed.

goos: darwin
goarch: arm64
pkg: github.com/grafana/pyroscope-go/godeltaprof/compat
                                      │   old.txt   │               new.txt                │
                                      │   sec/op    │    sec/op      vs base               │
HeapCompression-8                       691.1µ ± 0%    729.8µ ± 65%   +5.59% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   640.6µ ± 1%    693.8µ ±  9%   +8.30% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   643.2µ ± 1%    690.3µ ±  1%   +7.33% (p=0.002 n=6)
HeapDelta-8                             76.26µ ± 1%   113.92µ ±  2%  +49.38% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8         48.98µ ± 1%    81.11µ ±  2%  +65.59% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8         49.03µ ± 1%    81.14µ ±  1%  +65.49% (p=0.002 n=6)
geomean                                 193.3µ         253.0µ        +30.87%

                                      │   old.txt    │               new.txt               │
                                      │     B/op     │     B/op      vs base               │
HeapCompression-8                       974.1Ki ± 0%   973.9Ki ± 0%   -0.03% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   974.6Ki ± 0%   974.3Ki ± 0%   -0.02% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   974.6Ki ± 0%   974.3Ki ± 0%   -0.03% (p=0.002 n=6)
HeapDelta-8                              333.00 ± 0%     53.00 ± 0%  -84.08% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8          312.00 ± 0%     30.00 ± 0%  -90.38% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8          312.00 ± 0%     30.00 ± 0%  -90.38% (p=0.002 n=6)
geomean                                 17.42Ki        5.874Ki       -66.28%

                                      │  old.txt   │              new.txt              │
                                      │ allocs/op  │ allocs/op   vs base               │
HeapCompression-8                       788.0 ± 0%   787.0 ± 0%   -0.13% (p=0.002 n=6)
MutexCompression/ScalerMutexProfile-8   788.0 ± 0%   787.0 ± 0%   -0.13% (p=0.002 n=6)
MutexCompression/ScalerBlockProfile-8   788.0 ± 0%   787.0 ± 0%   -0.13% (p=0.002 n=6)
HeapDelta-8                             2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
MutexDelta/ScalerMutexProfile-8         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
MutexDelta/ScalerBlockProfile-8         2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
geomean                                 39.70        28.05       -29.33%

So it looks like the cost of deduplication is about 5% of overall time(including compression), which is not that bad.

godeltaprof/internal/pprof/delta_heap.go Outdated Show resolved Hide resolved
godeltaprof/internal/pprof/delta_heap.go Outdated Show resolved Hide resolved
godeltaprof/internal/pprof/delta_heap.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kolesnikovae kolesnikovae left a comment

Choose a reason for hiding this comment

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

LGTM. Nice job!

@korniltsev korniltsev merged commit 181f95a into main Jun 4, 2024
7 checks passed
@korniltsev korniltsev deleted the korniltsev/gotip-fix-mutex-tests branch June 4, 2024 05:57
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.

godeltaprof tests are failing on gotip
2 participants