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(storage): improve scanning with GLSN #715

Merged
merged 1 commit into from
Feb 26, 2024
Merged

Conversation

ijsong
Copy link
Member

@ijsong ijsong commented Feb 22, 2024

What this PR does

This PR substantially enhances the performance of GLSN-based log scanning in
Varlog's storage layer by shifting from point lookups to an iterator approach.
While introducing a minimal overhead of one additional object allocation, this
modification significantly reduces operation times and increases throughput for
larger scan sizes. The slight increase in object allocation is a small trade-off
for the significant performance gains achieved, as demonstrated by the
benchmark.

goos: darwin
goarch: amd64
pkg: github.com/kakao/varlog/internal/storage
cpu: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
                                    │    base     │                diff                 │
                                    │   sec/op    │   sec/op     vs base                │
Storage_ScanWithGLSN/numLogs=1-8      2.298µ ± 1%   3.088µ ± 1%  +34.36% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=10-8     9.682µ ± 1%   7.499µ ± 1%  -22.55% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=100-8    89.18µ ± 2%   49.93µ ± 0%  -44.01% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=1000-8   968.2µ ± 2%   472.4µ ± 0%  -51.21% (p=0.000 n=20)
geomean                               37.23µ        27.18µ       -26.98%

                                    │     base     │                diff                 │
                                    │     B/op     │     B/op      vs base               │
Storage_ScanWithGLSN/numLogs=1-8        120.0 ± 0%     128.0 ± 0%  +6.67% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=10-8       264.0 ± 0%     272.5 ± 0%  +3.22% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=100-8    1.669Ki ± 0%   1.676Ki ± 0%  +0.41% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=1000-8   15.78Ki ± 0%   15.77Ki ± 0%  -0.06% (p=0.000 n=20)
geomean                                 967.1          991.5       +2.53%

                                    │    base     │                diff                 │
                                    │  allocs/op  │  allocs/op   vs base                │
Storage_ScanWithGLSN/numLogs=1-8       5.000 ± 0%    6.000 ± 0%  +20.00% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=10-8      14.00 ± 0%    15.00 ± 0%   +7.14% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=100-8     104.0 ± 0%    105.0 ± 0%   +0.96% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=1000-8   1.004k ± 0%   1.005k ± 0%   +0.10% (p=0.000 n=20)
geomean                                52.00         55.51        +6.77%

Benchmark results summary:

  • Environment: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz, goos: darwin, goarch:
    amd64
  • Performance and memory efficiency both improve as the number of logs
    increases. Initial setup overhead results in a performance outlier for 1 log.
    However, significant enhancements are observed for larger log counts: 22.55%
    for 10 logs, 44.01% for 100 logs, and 51.21% for 1000 logs. These improvements
    highlight the method's scalability, with memory allocations remaining stable
    or even reducing, against expectations. The geometric mean shows only a 2.53%
    increase in bytes per operation and a 6.77% increase in allocations per
    operation, underscoring the approach's effectiveness in optimizing performance
    and memory usage.

These results demonstrate the scalability and efficiency of using a pebble
iterator for GLSN-based log scanning. The changes lead to a geomean throughput
increase of -26.98%, highlighting substantial performance improvements for
larger scan sizes without considerable memory overhead.

Additionally, the insights gained from this optimization present an opportunity
to rethink the Read RPC for more efficient log entry lookup by log sequence
number. However, this exploration is beyond the current scope of work.

@ijsong ijsong requested a review from hungryjang as a code owner February 22, 2024 16:34
Copy link

codecov bot commented Feb 22, 2024

Codecov Report

Attention: Patch coverage is 71.87500% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 49.84%. Comparing base (2fb6b53) to head (e0ef909).
Report is 1 commits behind head on main.

❗ Current head e0ef909 differs from pull request most recent head 963d10f. Consider uploading reports for the commit 963d10f to get more accurate results

Files Patch % Lines
internal/storage/scanner.go 71.87% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #715      +/-   ##
==========================================
+ Coverage   49.79%   49.84%   +0.04%     
==========================================
  Files         235      235              
  Lines       20651    20675      +24     
==========================================
+ Hits        10284    10305      +21     
- Misses       9729     9732       +3     
  Partials      638      638              

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

@ijsong ijsong force-pushed the benchmark_storage_scanwithglsn branch from cdaa7ac to 2fb6b53 Compare February 26, 2024 14:27
@ijsong ijsong force-pushed the perf_storage_scanwithglsn branch from 670d854 to e0ef909 Compare February 26, 2024 14:36
@ijsong
Copy link
Member Author

ijsong commented Feb 26, 2024

Merge activity

  • Feb 26, 10:00 AM EST: @ijsong started a stack merge that includes this pull request via Graphite.
  • Feb 26, 10:01 AM EST: Graphite rebased this pull request as part of a merge.
  • Feb 26, 10:08 AM EST: @ijsong merged this pull request with Graphite.

Base automatically changed from benchmark_storage_scanwithglsn to main February 26, 2024 15:00
This PR substantially enhances the performance of GLSN-based log scanning in
Varlog's storage layer by shifting from point lookups to an iterator approach.
While introducing a minimal overhead of one additional object allocation, this
modification significantly reduces operation times and increases throughput for
larger scan sizes. The slight increase in object allocation is a small trade-off
for the significant performance gains achieved, as demonstrated by the
benchmark.

```
goos: darwin
goarch: amd64
pkg: github.com/kakao/varlog/internal/storage
cpu: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
                                    │    base     │                diff                 │
                                    │   sec/op    │   sec/op     vs base                │
Storage_ScanWithGLSN/numLogs=1-8      2.298µ ± 1%   3.088µ ± 1%  +34.36% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=10-8     9.682µ ± 1%   7.499µ ± 1%  -22.55% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=100-8    89.18µ ± 2%   49.93µ ± 0%  -44.01% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=1000-8   968.2µ ± 2%   472.4µ ± 0%  -51.21% (p=0.000 n=20)
geomean                               37.23µ        27.18µ       -26.98%

                                    │     base     │                diff                 │
                                    │     B/op     │     B/op      vs base               │
Storage_ScanWithGLSN/numLogs=1-8        120.0 ± 0%     128.0 ± 0%  +6.67% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=10-8       264.0 ± 0%     272.5 ± 0%  +3.22% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=100-8    1.669Ki ± 0%   1.676Ki ± 0%  +0.41% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=1000-8   15.78Ki ± 0%   15.77Ki ± 0%  -0.06% (p=0.000 n=20)
geomean                                 967.1          991.5       +2.53%

                                    │    base     │                diff                 │
                                    │  allocs/op  │  allocs/op   vs base                │
Storage_ScanWithGLSN/numLogs=1-8       5.000 ± 0%    6.000 ± 0%  +20.00% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=10-8      14.00 ± 0%    15.00 ± 0%   +7.14% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=100-8     104.0 ± 0%    105.0 ± 0%   +0.96% (p=0.000 n=20)
Storage_ScanWithGLSN/numLogs=1000-8   1.004k ± 0%   1.005k ± 0%   +0.10% (p=0.000 n=20)
geomean                                52.00         55.51        +6.77%
```

Benchmark results summary:
- Environment: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz, goos: darwin, goarch:
  amd64
- Performance and memory efficiency both improve as the number of logs
  increases. Initial setup overhead results in a performance outlier for 1 log.
  However, significant enhancements are observed for larger log counts: 22.55%
  for 10 logs, 44.01% for 100 logs, and 51.21% for 1000 logs. These improvements
  highlight the method's scalability, with memory allocations remaining stable
  or even reducing, against expectations. The geometric mean shows only a 2.53%
  increase in bytes per operation and a 6.77% increase in allocations per
  operation, underscoring the approach's effectiveness in optimizing performance
  and memory usage.

These results demonstrate the scalability and efficiency of using a pebble
iterator for GLSN-based log scanning. The changes lead to a geomean throughput
increase of -26.98%, highlighting substantial performance improvements for
larger scan sizes without considerable memory overhead.

Additionally, the insights gained from this optimization present an opportunity
to rethink the Read RPC for more efficient log entry lookup by log sequence
number. However, this exploration is beyond the current scope of work.
@ijsong ijsong force-pushed the perf_storage_scanwithglsn branch from e0ef909 to 963d10f Compare February 26, 2024 15:00
@ijsong ijsong merged commit 3caaa0a into main Feb 26, 2024
9 checks passed
@ijsong ijsong deleted the perf_storage_scanwithglsn branch February 26, 2024 15:08
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