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

perf(metarepos): add mrpb.StorageNodeUncommitReport pool #446

Merged
merged 1 commit into from
Jun 1, 2023

Conversation

ijsong
Copy link
Member

@ijsong ijsong commented May 16, 2023

What this PR does

This patch adds an mrpb.StorageNodeUncommitReport pool, which is
proto/mrpb.storageNodeUncommitReportPool. It reduces heap objects allocated repeatedly whenever
processing reports received from storage nodes.

Below heap profiling is the previous result.

      flat  flat%   sum%        cum   cum%
  70865580  8.38% 44.73%   71293773  8.43%  github.com/kakao/varlog/internal/metarepos.(*reportCollectExecutor).processReport

Now here it is after applying this patch.

      flat  flat%   sum%        cum   cum%
  20734504  2.10% 75.92%   42122814  4.26%  github.com/kakao/varlog/internal/metarepos.(*reportCollectExecutor).processReport

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (626fe12) 63.24% compared to head (fe4c70e) 63.25%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@                   Coverage Diff                    @@
##           mr_remove_otel_label     #446      +/-   ##
========================================================
+ Coverage                 63.24%   63.25%   +0.01%     
========================================================
  Files                       131      131              
  Lines                     17914    17914              
========================================================
+ Hits                      11329    11332       +3     
  Misses                     6017     6017              
+ Partials                    568      565       -3     
Impacted Files Coverage Δ
internal/metarepos/report_collector.go 77.76% <100.00%> (+0.43%) ⬆️

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@hungryjang hungryjang left a comment

Choose a reason for hiding this comment

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

Good!

This patch adds an `mrpb.StorageNodeUncommitReport` pool, which is
`proto/mrpb.storageNodeUncommitReportPool`. It reduces heap objects allocated repeatedly whenever
processing reports received from storage nodes.

Below heap profiling is the previous result.

```
      flat  flat%   sum%        cum   cum%
  70865580  8.38% 44.73%   71293773  8.43%  github.com/kakao/varlog/internal/metarepos.(*reportCollectExecutor).processReport
```

Now here it is after applying this patch.

```
      flat  flat%   sum%        cum   cum%
  20734504  2.10% 75.92%   42122814  4.26%  github.com/kakao/varlog/internal/metarepos.(*reportCollectExecutor).processReport
```
@ijsong
Copy link
Member Author

ijsong commented Jun 1, 2023

@ijsong started a stack merge that includes this pull request via Graphite.

Base automatically changed from mr_remove_otel_label to main June 1, 2023 05:27
@ijsong ijsong merged commit 60f2cfe into main Jun 1, 2023
@ijsong
Copy link
Member Author

ijsong commented Jun 1, 2023

@ijsong merged this pull request with Graphite.

@ijsong ijsong deleted the mr_uncommit_report_pool branch June 1, 2023 05:27
ijsong added a commit that referenced this pull request Jul 20, 2023
This change makes mrpb.StorageNodeUncommitReport is reused when it is replaced with a new one.
Previous PR, #446, introduced a pool for mrpb.StorageNodeUncommitReport. However, the old
StorageNodeUncommitReport stored to reportContext was not reused, and this PR improves it.

To release the StorageNodeUncommitReport registered to reportContext, some methods of reportContext
are changed:

- (*reportContext).getReport returns a value of StorageNodeUncommitReport rather than a pointer. It
  makes releasing the StorageNodeUncommitReport happen at any time.
- add (*reportContext).swapReport to set a new StorageNodeUncommitReport and get the old one
  simultaneously.
- getReport and swapReport return the boolean result to indicate whether the result report is zero
  value.

BenchmarkSwapReport evaluates the performance improvements of this change.

- getAndSavePtr: Previous implementation.
- getAndSave: Call getReport and saveReport.
- swap: Call swapReport.

```
BenchmarkSwapReport/getAndSavePtr-16         	 5947423	       207.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6220454	       198.7 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6133489	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6131910	       199.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 5592459	       201.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6180243	       200.1 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6172357	       199.2 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6211966	       198.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6095289	       198.3 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6043491	       197.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6143407	       200.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 5938540	       203.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6162986	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6172598	       197.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6105918	       197.0 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6077460	       196.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 5953898	       197.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6131799	       199.9 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6139296	       200.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6115653	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/swap-16                  	35501544	        33.83 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35982945	        34.05 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36518960	        34.21 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	34620783	        34.52 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35967453	        33.88 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36135454	        34.17 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	34492548	        35.16 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35581888	        34.14 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	32028504	        33.78 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36024037	        33.94 ns/op	       0 B/op	       0 allocs/op
```
ijsong added a commit that referenced this pull request Jul 28, 2023
This change makes mrpb.StorageNodeUncommitReport is reused when it is replaced with a new one.
Previous PR, #446, introduced a pool for mrpb.StorageNodeUncommitReport. However, the old
StorageNodeUncommitReport stored to reportContext was not reused, and this PR improves it.

To release the StorageNodeUncommitReport registered to reportContext, some methods of reportContext
are changed:

- (*reportContext).getReport returns a value of StorageNodeUncommitReport rather than a pointer. It
  makes releasing the StorageNodeUncommitReport happen at any time.
- add (*reportContext).swapReport to set a new StorageNodeUncommitReport and get the old one
  simultaneously.
- getReport and swapReport return the boolean result to indicate whether the result report is zero
  value.

BenchmarkSwapReport evaluates the performance improvements of this change.

- getAndSavePtr: Previous implementation.
- getAndSave: Call getReport and saveReport.
- swap: Call swapReport.

```
BenchmarkSwapReport/getAndSavePtr-16         	 5947423	       207.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6220454	       198.7 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6133489	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6131910	       199.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 5592459	       201.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6180243	       200.1 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6172357	       199.2 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6211966	       198.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6095289	       198.3 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6043491	       197.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6143407	       200.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 5938540	       203.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6162986	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6172598	       197.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6105918	       197.0 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6077460	       196.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 5953898	       197.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6131799	       199.9 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6139296	       200.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6115653	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/swap-16                  	35501544	        33.83 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35982945	        34.05 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36518960	        34.21 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	34620783	        34.52 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35967453	        33.88 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36135454	        34.17 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	34492548	        35.16 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35581888	        34.14 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	32028504	        33.78 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36024037	        33.94 ns/op	       0 B/op	       0 allocs/op
```
ijsong added a commit that referenced this pull request Jul 28, 2023
This change makes mrpb.StorageNodeUncommitReport is reused when it is replaced with a new one.
Previous PR, #446, introduced a pool for mrpb.StorageNodeUncommitReport. However, the old
StorageNodeUncommitReport stored to reportContext was not reused, and this PR improves it.

To release the StorageNodeUncommitReport registered to reportContext, some methods of reportContext
are changed:

- (*reportContext).getReport returns a value of StorageNodeUncommitReport rather than a pointer. It
  makes releasing the StorageNodeUncommitReport happen at any time.
- add (*reportContext).swapReport to set a new StorageNodeUncommitReport and get the old one
  simultaneously.
- getReport and swapReport return the boolean result to indicate whether the result report is zero
  value.

BenchmarkSwapReport evaluates the performance improvements of this change.

- getAndSavePtr: Previous implementation.
- getAndSave: Call getReport and saveReport.
- swap: Call swapReport.

```
BenchmarkSwapReport/getAndSavePtr-16         	 5947423	       207.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6220454	       198.7 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6133489	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6131910	       199.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 5592459	       201.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6180243	       200.1 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6172357	       199.2 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6211966	       198.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6095289	       198.3 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16         	 6043491	       197.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6143407	       200.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 5938540	       203.6 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6162986	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6172598	       197.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6105918	       197.0 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6077460	       196.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 5953898	       197.8 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6131799	       199.9 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6139296	       200.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/getAndSave-16            	 6115653	       198.5 ns/op	      32 B/op	       1 allocs/op
BenchmarkSwapReport/swap-16                  	35501544	        33.83 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35982945	        34.05 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36518960	        34.21 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	34620783	        34.52 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35967453	        33.88 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36135454	        34.17 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	34492548	        35.16 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	35581888	        34.14 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	32028504	        33.78 ns/op	       0 B/op	       0 allocs/op
BenchmarkSwapReport/swap-16                  	36024037	        33.94 ns/op	       0 B/op	       0 allocs/op
```
ijsong added a commit that referenced this pull request Jul 28, 2023
…537)

### What this PR does

This change makes mrpb.StorageNodeUncommitReport is reused when it is replaced with a new one.
Previous PR, #446, introduced a pool for mrpb.StorageNodeUncommitReport. However, the old
StorageNodeUncommitReport stored to reportContext was not reused, and this PR improves it.

To release the StorageNodeUncommitReport registered to reportContext, some methods of reportContext
are changed:

- (*reportContext).getReport returns a value of StorageNodeUncommitReport rather than a pointer. It
  makes releasing the StorageNodeUncommitReport happen at any time.
- add (*reportContext).swapReport to set a new StorageNodeUncommitReport and get the old one
  simultaneously.
- getReport and swapReport return the boolean result to indicate whether the result report is zero
  value.

BenchmarkSwapReport evaluates the performance improvements of this change.

- getAndSavePtr: Previous implementation.
- getAndSave: Call getReport and saveReport.
- swap: Call swapReport.

```
BenchmarkSwapReport/getAndSavePtr-16             5947423               207.8 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6220454               198.7 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6133489               198.5 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6131910               199.8 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             5592459               201.6 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6180243               200.1 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6172357               199.2 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6211966               198.6 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6095289               198.3 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSavePtr-16             6043491               197.6 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6143407               200.6 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                5938540               203.6 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6162986               198.5 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6172598               197.8 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6105918               197.0 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6077460               196.5 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                5953898               197.8 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6131799               199.9 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6139296               200.5 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/getAndSave-16                6115653               198.5 ns/op            32 B/op          1 allocs/op
BenchmarkSwapReport/swap-16                     35501544                33.83 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     35982945                34.05 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     36518960                34.21 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     34620783                34.52 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     35967453                33.88 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     36135454                34.17 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     34492548                35.16 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     35581888                34.14 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     32028504                33.78 ns/op            0 B/op          0 allocs/op
BenchmarkSwapReport/swap-16                     36024037                33.94 ns/op            0 B/op          0 allocs/op
```
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