fstree: optimize GetRange operation#3438
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3438 +/- ##
==========================================
+ Coverage 21.24% 21.49% +0.24%
==========================================
Files 707 704 -3
Lines 53069 52447 -622
==========================================
- Hits 11275 11272 -3
+ Misses 40959 40338 -621
- Partials 835 837 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| n, err = seeker.Seek(int64(from), io.SeekStart) | ||
| } else { | ||
| to = pLen | ||
| n, err = io.CopyN(io.Discard, reader, int64(from)) |
There was a problem hiding this comment.
I think you can implement proper Seek() for payloadReader, it'll be faster (position the buffer reader and/or seek in the file) and it can be useful in future as well (think of resetting the stream after transmission).
| if length != 0 { | ||
| to = from + length | ||
| var n int64 | ||
| if seeker, ok := reader.(io.Seeker); ok { |
There was a problem hiding this comment.
If from is zero it's not needed.
cthulhu-rider
left a comment
There was a problem hiding this comment.
@End-rey we lack unit tests. How about adding them?
7e35fc9 to
692e131
Compare
And which ones are missing? The tests for |
692e131 to
7f1a8b7
Compare
oh, missed that tests are packaged separately. Then ok |
cthulhu-rider
left a comment
There was a problem hiding this comment.
tests are good lookin now, easy to analyse 👍
noticable thing is 4K with ~10% lower speed and memory space
FSTree_GetRange/size=4KB,off=Empty,len=4KB/regular-16 17.62Ki ± 0% 48.31Ki ± 0% +174.24% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=Empty,len=4KB/compressed-16 17.62Ki ± 0% 48.31Ki ± 0% +174.24% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=Empty,len=4KB/combined-16 17.90Ki ± 0% 48.08Ki ± 0% +168.60% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=Empty,len=Empty/regular-16 17.77Ki ± 0% 47.95Ki ± 0% +169.80% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=Empty,len=Empty/compressed-16 17.77Ki ± 0% 47.95Ki ± 0% +169.80% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=Empty,len=Empty/combined-16 17.91Ki ± 0% 48.13Ki ± 0% +168.81% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=1KB,len=1KB/regular-16 17.92Ki ± 0% 44.77Ki ± 0% +149.83% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=1KB,len=1KB/compressed-16 17.92Ki ± 0% 44.77Ki ± 0% +149.83% (p=0.000 n=10)
FSTree_GetRange/size=4KB,off=1KB,len=1KB/combined-16 17.95Ki ± 1% 45.13Ki ± 0% +151.45% (p=0.000 n=10)
have u tested 1M or 4M? It's too big step b/w 4K and 10M imo
btw off=Empty,len=Empty: unlike len, off=Empty is understandable but looks a bit weird to me
Signed-off-by: Andrey Butusov <andrey@nspcc.io>
7f1a8b7 to
766d39b
Compare
766d39b to
c475a6b
Compare
Since #3383 and #3431, it is now not necessary to unmarshal the object to get its payload, and we can read the payload from reader to find the data. ``` goos: linux goarch: amd64 pkg: github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ FSTree_GetRange/size=10MB,off=1MB,len=4KB/regular-16 8027.9µ ± 9% 264.8µ ± 5% -96.70% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=1MB,len=4KB/compressed-16 7608.3µ ± 5% 270.5µ ± 6% -96.45% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=1MB,len=4KB/combined-16 7391.8µ ± 6% 360.6µ ± 8% -95.12% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/regular-16 7.876m ± 4% 4.134m ± 3% -47.52% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/compressed-16 7.989m ± 6% 4.170m ± 3% -47.80% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/combined-16 7.530m ± 2% 4.038m ± 8% -46.37% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/regular-16 8.220m ± 6% 4.164m ± 4% -49.35% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/compressed-16 8.183m ± 6% 4.703m ± 6% -42.53% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/combined-16 7.508m ± 5% 4.325m ± 5% -42.40% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/regular-16 822.54µ ± 6% 83.04µ ± 4% -89.90% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/compressed-16 884.94µ ± 7% 92.61µ ± 5% -89.53% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/combined-16 1346.99µ ± 11% 84.62µ ± 10% -93.72% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/regular-16 908.2µ ± 15% 817.8µ ± 9% ~ (p=0.165 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/compressed-16 946.3µ ± 3% 806.2µ ± 4% -14.80% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/combined-16 1290.4µ ± 9% 914.6µ ± 11% -29.12% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/regular-16 955.0µ ± 3% 863.4µ ± 4% -9.60% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/compressed-16 948.7µ ± 4% 869.5µ ± 5% -8.35% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/combined-16 1318.8µ ± 13% 955.9µ ± 7% -27.52% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/regular-16 79.55µ ± 5% 89.11µ ± 2% +12.01% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/compressed-16 78.48µ ± 5% 87.90µ ± 2% +12.01% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/combined-16 79.15µ ± 4% 92.59µ ± 3% +16.98% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/regular-16 81.78µ ± 4% 92.22µ ± 4% +12.77% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/compressed-16 79.80µ ± 11% 90.99µ ± 3% +14.02% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/combined-16 92.39µ ± 9% 92.73µ ± 2% ~ (p=0.280 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/regular-16 92.11µ ± 1% 89.30µ ± 2% -3.06% (p=0.002 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/compressed-16 80.11µ ± 17% 91.34µ ± 2% ~ (p=0.105 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/combined-16 79.40µ ± 5% 90.61µ ± 4% +14.12% (p=0.000 n=10) geomean 871.6µ 399.9µ -54.12% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ FSTree_GetRange/size=10MB,off=1MB,len=4KB/regular-16 20495.77Ki ± 0% 43.65Ki ± 0% -99.79% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=1MB,len=4KB/compressed-16 20495.77Ki ± 0% 43.65Ki ± 0% -99.79% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=1MB,len=4KB/combined-16 20496.00Ki ± 0% 43.81Ki ± 0% -99.79% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/regular-16 20.02Mi ± 0% 10.04Mi ± 0% -49.84% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/compressed-16 20.02Mi ± 0% 10.04Mi ± 0% -49.84% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/combined-16 20.02Mi ± 0% 10.04Mi ± 0% -49.84% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/regular-16 20.02Mi ± 0% 10.04Mi ± 0% -49.84% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/compressed-16 20.02Mi ± 0% 10.04Mi ± 0% -49.84% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/combined-16 20.02Mi ± 0% 10.04Mi ± 0% -49.85% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/regular-16 2063.83Ki ± 0% 43.65Ki ± 0% -97.89% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/compressed-16 2063.83Ki ± 0% 43.65Ki ± 0% -97.88% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/combined-16 2063.98Ki ± 0% 43.89Ki ± 0% -97.87% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/regular-16 2.015Mi ± 0% 1.039Mi ± 0% -48.45% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/compressed-16 2.015Mi ± 0% 1.039Mi ± 0% -48.45% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/combined-16 2.016Mi ± 0% 1.039Mi ± 0% -48.46% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/regular-16 2.015Mi ± 0% 1.039Mi ± 0% -48.44% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/compressed-16 2.015Mi ± 0% 1.039Mi ± 0% -48.44% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/combined-16 2.016Mi ± 0% 1.039Mi ± 0% -48.46% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/regular-16 17.97Ki ± 0% 47.68Ki ± 0% +165.35% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/compressed-16 17.97Ki ± 0% 47.68Ki ± 0% +165.35% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/combined-16 17.91Ki ± 0% 48.13Ki ± 0% +168.71% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/regular-16 18.12Ki ± 0% 48.09Ki ± 0% +165.42% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/compressed-16 18.12Ki ± 0% 48.09Ki ± 0% +165.42% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/combined-16 17.90Ki ± 1% 48.12Ki ± 0% +168.78% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/regular-16 18.15Ki ± 0% 45.07Ki ± 0% +148.34% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/compressed-16 18.15Ki ± 0% 45.07Ki ± 0% +148.34% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/combined-16 17.92Ki ± 1% 45.11Ki ± 0% +151.67% (p=0.000 n=10) geomean 913.5Ki 306.3Ki -66.47% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ FSTree_GetRange/size=10MB,off=1MB,len=4KB/regular-16 135.0 ± 0% 138.0 ± 0% +2.22% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=1MB,len=4KB/compressed-16 135.0 ± 0% 138.0 ± 0% +2.22% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=1MB,len=4KB/combined-16 140.0 ± 1% 140.5 ± 1% +0.36% (p=0.038 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/regular-16 142.0 ± 0% 145.0 ± 0% +2.11% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/compressed-16 142.0 ± 0% 145.0 ± 0% +2.11% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=10MB/combined-16 138.0 ± 1% 140.5 ± 2% ~ (p=0.063 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/regular-16 139.0 ± 0% 148.0 ± 0% +6.47% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/compressed-16 139.0 ± 0% 148.0 ± 0% +6.47% (p=0.000 n=10) FSTree_GetRange/size=10MB,off=Empty,len=Empty/combined-16 139.0 ± 2% 139.0 ± 1% ~ (p=0.773 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/regular-16 135.0 ± 0% 134.0 ± 0% -0.74% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/compressed-16 135.0 ± 0% 134.0 ± 0% -0.74% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=1KB,len=4KB/combined-16 139.5 ± 2% 140.5 ± 2% +0.72% (p=0.030 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/regular-16 127.0 ± 0% 141.0 ± 0% +11.02% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/compressed-16 127.0 ± 0% 141.0 ± 0% +11.02% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=1MB/combined-16 138.0 ± 2% 139.5 ± 1% ~ (p=0.195 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/regular-16 127.0 ± 0% 144.0 ± 0% +13.39% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/compressed-16 127.0 ± 0% 144.0 ± 0% +13.39% (p=0.000 n=10) FSTree_GetRange/size=1MB,off=Empty,len=Empty/combined-16 139.0 ± 1% 140.0 ± 2% ~ (p=0.146 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/regular-16 139.0 ± 0% 129.0 ± 0% -7.19% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/compressed-16 139.0 ± 0% 129.0 ± 0% -7.19% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=4KB/combined-16 138.0 ± 1% 140.5 ± 1% +1.81% (p=0.001 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/regular-16 142.0 ± 0% 140.0 ± 0% -1.41% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/compressed-16 142.0 ± 0% 140.0 ± 0% -1.41% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=Empty,len=Empty/combined-16 137.5 ± 3% 140.0 ± 2% ~ (p=0.091 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/regular-16 143.0 ± 0% 140.0 ± 0% -2.10% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/compressed-16 143.0 ± 0% 140.0 ± 0% -2.10% (p=0.000 n=10) FSTree_GetRange/size=4KB,off=1KB,len=1KB/combined-16 138.0 ± 1% 140.5 ± 2% +1.81% (p=0.030 n=10) geomean 137.1 139.9 +2.01% ``` Closes #1724. Signed-off-by: Andrey Butusov <andrey@nspcc.io>
Closes #1724.
Do we need to leave the benchmark test for the old and new Range? Or should I remove it from the commit?