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): reuse mrpb.StorageNodeUncommitReport while changed #537

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

ijsong
Copy link
Member

@ijsong ijsong commented Jul 20, 2023

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

@ijsong ijsong self-assigned this Jul 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02% ⚠️

Comparison is base (be9f121) 61.82% compared to head (57d8039) 61.81%.

❗ 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_raftentry_pool     #537      +/-   ##
=====================================================
- Coverage              61.82%   61.81%   -0.02%     
=====================================================
  Files                    137      137              
  Lines                  18640    18656      +16     
=====================================================
+ Hits                   11524    11532       +8     
- Misses                  6546     6552       +6     
- Partials                 570      572       +2     
Files Changed Coverage Δ
internal/metarepos/report_collector.go 77.41% <100.00%> (-0.35%) ⬇️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

That's something I didn't even think of. Is there any way to make diff.UncommitReports using pool?

@ijsong
Copy link
Member Author

ijsong commented Jul 27, 2023

That's something I didn't even think of. Is there any way to make diff.UncommitReports using pool?

@hungryjang, using sync.Pool for diff.UncommitReports looks promising, but the variable length makes using the pool difficult.
However, there are a few tricks you can try:

  • Pooling of growable diff.UncommitReports: there will usually be an upper bound on the length.
  • Use hard limit: In rare cases where the length of diff.UncommitReports can be increased than expected; we can shrink and reclaim it to the pool.
  • Use reuse cycle: When the number of reusing the diff.UncommitReports is greater than the given parameter; we can discard it.

I am not convinced the above logic works well. However, some of them are being used for other open-source projects.

@ijsong ijsong force-pushed the mr_reuse_storagenode_uncommit_report branch from 519cd60 to 25fd847 Compare July 28, 2023 01:25
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 ijsong force-pushed the mr_reuse_storagenode_uncommit_report branch from 25fd847 to 57d8039 Compare July 28, 2023 03:58
@ijsong
Copy link
Member Author

ijsong commented Jul 28, 2023

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

Base automatically changed from mr_raftentry_pool to main July 28, 2023 05:13
@ijsong ijsong merged commit 8f6e097 into main Jul 28, 2023
8 checks passed
@ijsong ijsong deleted the mr_reuse_storagenode_uncommit_report branch July 28, 2023 05:13
@ijsong
Copy link
Member Author

ijsong commented Jul 28, 2023

@ijsong merged this pull request with Graphite.

ijsong added a commit that referenced this pull request Aug 7, 2023
🤖 I have created a release *beep* *boop*
---


## [0.15.0](v0.14.1...v0.15.0) (2023-07-31)


### Features

* **admin:** add otelgrpc metric interceptor ([d9ca9aa](d9ca9aa))
* **admin:** add otelgrpc metric interceptor ([#509](#509)) ([db7a1a2](db7a1a2))
* **admin:** speed up fetching cluster metadata ([3e46f62](3e46f62))
* **admin:** speed up fetching cluster metadata ([#480](#480)) ([53a8f19](53a8f19))
* **all:** add common flags for telemetry ([fcacd1a](fcacd1a))
* **all:** add common flags for telemetry ([#494](#494)) ([63355e9](63355e9))
* **benchmark:** share a connection between appenders in a target ([7dc53e9](7dc53e9))
* **benchmark:** share a connection between appenders in a target ([#524](#524)) ([2cd9196](2cd9196))
* **client:** add Clear to the log stream appender manager ([9a89065](9a89065))
* **client:** add Clear to the log stream appender manager ([#514](#514)) ([e5b6a2e](e5b6a2e))
* **storagenode:** add --storage-trim-delay to set a delay before the deletion of log entries ([db39713](db39713))
* **storagenode:** add --storage-trim-delay to set a delay before the deletion of log entries ([#529](#529)) ([015bfa4](015bfa4))
* **storagenode:** add --storage-trim-rate to set throttling rate of Trim ([83b7496](83b7496))
* **storagenode:** add --storage-trim-rate to set throttling rate of Trim ([#530](#530)) ([6e69306](6e69306))
* **telemetry:** customize bucket size of process.runtime.go.gc.pause_ns ([b181132](b181132))
* **telemetry:** customize bucket size of process.runtime.go.gc.pause_ns ([#510](#510)) ([9d99520](9d99520))
* **telemetry:** customize bucket size of rpc.server.duration ([a0e5973](a0e5973))
* **telemetry:** customize bucket size of rpc.server.duration ([#511](#511)) ([e41fe1c](e41fe1c))


### Bug Fixes

* **benchmark:** make append duration's precision high ([e3a091d](e3a091d))
* **benchmark:** make append duration's precision high ([#522](#522)) ([815af53](815af53))
* **benchmark:** support graceful stop ([8616d55](8616d55))
* **benchmark:** support graceful stop ([#527](#527)) ([fc4ed81](fc4ed81))
* **metarepos:** add TestMRIgnoreDirtyReport ([fe2a550](fe2a550))
* **metarepos:** allow set commitTick ([bdca20a](bdca20a))
* **metarepos:** ignore invalid report ([e8620de](e8620de))
* **storagenode:** ignore context error while checking to interleave of Append RPC errors ([04d1052](04d1052))
* **storagenode:** ignore context error while checking to interleave of Append RPC errors ([#504](#504)) ([5a7a3b0](5a7a3b0))
* **storagenode:** restore uncommitted logs ([267cccc](267cccc)), closes [#490](#490)
* **storagenode:** restore uncommitted logs ([#492](#492)) ([a9832ee](a9832ee)), closes [#490](#490)


### Performance Improvements

* **admin:** use singleflight to handle Admin's RPCs ([c231888](c231888))
* **admin:** use singleflight to handle Admin's RPCs ([#482](#482)) ([1a6a96d](1a6a96d))
* **metarepos:** add a pool for []*mrpb.Report ([fa8c89d](fa8c89d))
* **metarepos:** add a pool for []*mrpb.Report ([#534](#534)) ([16b2181](16b2181))
* **metarepos:** add a pool for *mrpb.RaftEntry ([be9f121](be9f121))
* **metarepos:** add a pool for *mrpb.RaftEntry ([#536](#536)) ([96ab5e2](96ab5e2))
* **metarepos:** add a pool for mrpb.Reports ([59a6a5a](59a6a5a))
* **metarepos:** add a pool for mrpb.Reports ([#533](#533)) ([b227c75](b227c75))
* **metarepos:** avoid copy overhead by removing unnecessary converting from byte slice to string ([a775628](a775628))
* **metarepos:** avoid copy overhead by removing unnecessary converting from byte slice to string ([#532](#532)) ([1702769](1702769))
* **metarepos:** reuse mrpb.StorageNodeUncommitReport while changed ([57d8039](57d8039))
* **metarepos:** reuse mrpb.StorageNodeUncommitReport while changed ([#537](#537)) ([8f6e097](8f6e097))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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