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

pkg/metastore: Reduce allocs in kv.go #3136

Merged
merged 6 commits into from
Jun 3, 2023

Conversation

marselester
Copy link
Contributor

@marselester marselester commented May 16, 2023

This is a follow up PR related to #3064 to reduce allocations in NormalizeWriteRawRequest.

# new
BenchmarkMakeFunctionID-2   	  858595	      1447 ns/op	      96 B/op	       1 allocs/op
# old
BenchmarkMakeFunctionID-12    	  640981	      1804 ns/op	    1064 B/op	      12 allocs/op
# new
BenchmarkMakeMappingID-12    	 3670863	       323.4 ns/op	      48 B/op	       1 allocs/op
# old
BenchmarkMakeMappingID-12    	 2304825	       531.8 ns/op	     424 B/op	       8 allocs/op
# new
BenchmarkMakeStacktraceID-12    	  322155	      3702 ns/op	     144 B/op	       1 allocs/op
# old
BenchmarkMakeStacktraceID-12    	  228817	      5012 ns/op	    2864 B/op	      31 allocs/op

This helped NormalizeWriteRawRequest to shave 94 K allocs, 7.9 MB, and 6.4 ms per operation.

$ benchstat bench-old.txt bench-new.txt 
name                         old time/op    new time/op    delta
NormalizeWriteRawRequest-12    43.2ms ± 7%    36.8ms ± 7%  -14.82%  (p=0.000 n=49+46)

name                         old alloc/op   new alloc/op   delta
NormalizeWriteRawRequest-12    52.4MB ± 1%    44.5MB ± 1%  -15.20%  (p=0.000 n=50+50)

name                         old allocs/op  new allocs/op  delta
NormalizeWriteRawRequest-12      381k ± 0%      287k ± 1%  -24.70%  (p=0.000 n=50+50)

Together with just recently merged PRs we've got 125 K saving in allocations.

$ benchstat bench-very-old.txt bench-new.txt
name                         old time/op    new time/op    delta
NormalizeWriteRawRequest-12    43.9ms ± 7%    36.8ms ± 7%  -16.22%  (p=0.000 n=47+46)

name                         old alloc/op   new alloc/op   delta
NormalizeWriteRawRequest-12    53.5MB ± 1%    44.5MB ± 1%  -16.95%  (p=0.000 n=50+50)

name                         old allocs/op  new allocs/op  delta
NormalizeWriteRawRequest-12      412k ± 0%      287k ± 1%  -30.25%  (p=0.000 n=50+50)

@marselester marselester requested a review from a team as a code owner May 16, 2023 15:34
@marselester
Copy link
Contributor Author

Screenshot 2023-05-16 at 11 43 27
Parca logs
$ ./parca --debug-normalize-addresses=true
ooooooooo.
`888   `Y88.
 888   .d88'  .oooo.   oooo d8b  .ooooo.   .oooo.
 888ooo88P'  `P  )88b  `888""8P d88' `"Y8 `P  )88b
 888          .oP"888   888     888        .oP"888
 888         d8(  888   888     888   .o8 d8(  888
o888o        `Y888""8o d888b    `Y8bod8P' `Y888""8o



level=info name=parca ts=2023-05-16T15:42:29.122832471Z caller=factory.go:52 msg="loading bucket configuration"
level=info name=parca ts=2023-05-16T15:42:29.135311909Z caller=badger.go:54 msg="Set nextTxnTs to 0"
level=info name=parca ts=2023-05-16T15:42:29.146257111Z caller=server.go:93 msg="starting server" addr=:7070
level=error name=parca ts=2023-05-16T15:43:09.225809636Z caller=symbolizer.go:315 component=symbolizer msg="failed to remove liner file" err="remove /tmp/parca-symbolizer-3663392888: no such file or directory"
level=error name=parca ts=2023-05-16T15:43:49.190579342Z caller=symbolizer.go:315 component=symbolizer msg="failed to remove liner file" err="remove /tmp/parca-symbolizer-1907039591: no such file or directory"
Parca Agent logs
$ sudo ./dist/parca-agent --debug-normalize-addresses=false --remote-store-address=:7070 --remote-store-insecure
ooooooooo.                                                  .o.                                            .
`888   `Y88.                                               .888.                                         .o8
 888   .d88'  .oooo.   oooo d8b  .ooooo.   .oooo.         .8"888.      .oooooooo  .ooooo.  ooo. .oo.   .o888oo
 888ooo88P'  `P  )88b  `888""8P d88' `"Y8 `P  )88b       .8' `888.    888' `88b  d88' `88b `888P"Y88b    888
 888          .oP"888   888     888        .oP"888      .88ooo8888.   888   888  888ooo888  888   888    888
 888         d8(  888   888     888   .o8 d8(  888     .8'     `888.  `88bod8P'  888    .o  888   888    888 .
o888o        `Y888""8o d888b    `Y8bod8P' `Y888""8o   o88o     o8888o `8oooooo.  `Y8bod8P' o888o o888o   "888"
                                                                      d"     YD
                                                                      "Y88888P'

level=info name=parca-agent ts=2023-05-16T15:42:33.271743087Z caller=main.go:292 msg="maxprocs: Leaving GOMAXPROCS=2: CPU quota undefined"
level=info name=parca-agent ts=2023-05-16T15:42:33.283839489Z caller=main.go:334 msg="eBPF is supported and enabled by the host kernel"
name=parca-agent ts=2023-05-16T15:42:33.284664289Z caller=main.go:396 msg=starting... node=ubuntu-jammy store=:7070
level=info name=parca-agent ts=2023-05-16T15:42:33.286910742Z caller=main.go:499 msg=rlimit cur=1048576 max=1048575
level=info name=parca-agent ts=2023-05-16T15:42:33.295685422Z caller=cpu.go:224 msg="Attempting to create unwind shards" count=50

Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@kakkoyun kakkoyun merged commit 6ba6012 into parca-dev:main Jun 3, 2023
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.

2 participants