Optimize tree service GetSubTree latency #957

Closed
fyrchik wants to merge 5 commits from fyrchik/frostfs-node:optimize-list-latency into master

5 commits

Author SHA1 Message Date
8cbf9a0b44 [#957] treesvc: Use sorting when number of items is small
All checks were successful
DCO action / DCO (pull_request) Successful in 2m13s
Build / Build Components (1.20) (pull_request) Successful in 2m36s
Vulncheck / Vulncheck (pull_request) Successful in 3m1s
Build / Build Components (1.21) (pull_request) Successful in 4m7s
Tests and linters / Staticcheck (pull_request) Successful in 4m1s
Tests and linters / Tests (1.20) (pull_request) Successful in 6m13s
Tests and linters / Lint (pull_request) Successful in 7m12s
Tests and linters / Tests with -race (pull_request) Successful in 7m27s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m30s
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-02-06 14:14:50 +03:00
d18eaf060d [#957] treesvc: Implement pairing heap
With a large number of objects in a flat tree, sorting the nodes
dominates the latency of the operation. This scales nonlinearly
as O(n log n). Pairing heap has O(1) insert, and O(log n) extractMin,
which allows us to have O(n + log n) = O(n) latency on the first
operation, albeit with a slight increase in total running time.
On a real cluster with 2m objects, the latency decreased from 25s to
15s.

```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
                        │     cache     │               noparent               │
                        │    sec/op     │    sec/op     vs base                │
GetSubTree/latency-8      2349.9µ ± 19%   572.1µ ± 17%  -75.65% (p=0.000 n=10)
GetSubTree/total_time-8    70.62m ±  8%   86.02m ±  3%  +21.81% (p=0.000 n=10)
geomean                    12.88m         7.015m        -45.54%

                        │    cache     │               noparent               │
                        │     B/op     │     B/op      vs base                │
GetSubTree/latency-8      43.87Mi ± 0%   32.81Mi ± 0%  -25.22% (p=0.000 n=10)
GetSubTree/total_time-8   43.87Mi ± 0%   32.81Mi ± 0%  -25.22% (p=0.000 n=10)
geomean                   43.87Mi        32.81Mi       -25.22%

                        │    cache    │              noparent               │
                        │  allocs/op  │  allocs/op   vs base                │
GetSubTree/latency-8      400.0k ± 0%   500.0k ± 0%  +24.99% (p=0.000 n=10)
GetSubTree/total_time-8   400.0k ± 0%   500.0k ± 0%  +24.99% (p=0.000 n=10)
geomean                   400.0k        500.0k       +24.99%
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-02-06 14:14:49 +03:00
77bdadde14 [#957] treesvc/heap: Cache FileName attribute
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
                        │     new      │                cache                 │
                        │    sec/op    │    sec/op     vs base                │
GetSubTree/latency-8      4.059m ± 20%   2.350m ± 19%  -42.11% (p=0.000 n=10)
GetSubTree/total_time-8   78.82m ±  4%   70.62m ±  8%  -10.39% (p=0.001 n=10)
geomean                   17.89m         12.88m        -27.98%

                        │     new      │                cache                 │
                        │     B/op     │     B/op      vs base                │
GetSubTree/latency-8      32.81Mi ± 0%   43.87Mi ± 0%  +33.72% (p=0.000 n=10)
GetSubTree/total_time-8   32.81Mi ± 0%   43.87Mi ± 0%  +33.73% (p=0.000 n=10)
geomean                   32.81Mi        43.87Mi       +33.72%

                        │     new     │               cache                │
                        │  allocs/op  │  allocs/op   vs base               │
GetSubTree/latency-8      400.0k ± 0%   400.0k ± 0%  +0.01% (p=0.000 n=10)
GetSubTree/total_time-8   400.0k ± 0%   400.0k ± 0%  +0.01% (p=0.000 n=10)
geomean                   400.0k        400.0k       +0.01%
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-02-06 10:15:28 +03:00
3601feab81 [#957] treesvc: Abstract out Heap interface for listing
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
                        │     old      │                 new                  │
                        │    sec/op    │    sec/op     vs base                │
GetSubTree/latency-8      3.542m ± 12%   4.059m ± 20%  +14.59% (p=0.005 n=10)
GetSubTree/total_time-8   73.19m ±  9%   78.82m ±  4%   +7.69% (p=0.043 n=10)
geomean                   16.10m         17.89m        +11.09%

                        │     old      │                 new                  │
                        │     B/op     │     B/op      vs base                │
GetSubTree/latency-8      28.23Mi ± 0%   32.81Mi ± 0%  +16.22% (p=0.000 n=10)
GetSubTree/total_time-8   28.23Mi ± 0%   32.81Mi ± 0%  +16.22% (p=0.000 n=10)
geomean                   28.23Mi        32.81Mi       +16.22%

                        │     old     │                new                 │
                        │  allocs/op  │  allocs/op   vs base               │
GetSubTree/latency-8      400.0k ± 0%   400.0k ± 0%  +0.00% (p=0.000 n=10)
GetSubTree/total_time-8   400.0k ± 0%   400.0k ± 0%  +0.00% (p=0.000 n=10)
geomean                   400.0k        400.0k       +0.00%
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-02-06 10:14:35 +03:00
7eab9fcede [#957] treesvc: Add benchmark for getSubTree
```
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
BenchmarkGetSubTree/latency-8         	      16	   3074441 ns/op	29602255 B/op	  400010 allocs/op
BenchmarkGetSubTree/latency-8         	      15	   3318523 ns/op	29602739 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      16	   3195982 ns/op	29602004 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      15	   3584962 ns/op	29603457 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      15	   3623496 ns/op	29602061 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      15	   3346428 ns/op	29602054 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      16	   3965596 ns/op	29602029 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      12	   4439678 ns/op	29604445 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      15	   3499192 ns/op	29602053 B/op	  400009 allocs/op
BenchmarkGetSubTree/latency-8         	      14	   3896512 ns/op	29601542 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      15	  70107430 ns/op	29602047 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      13	  79811187 ns/op	29601585 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      15	  73591921 ns/op	29602068 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      15	  77711739 ns/op	29602047 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      15	  71107422 ns/op	29602140 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      15	  80340752 ns/op	29601606 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      16	  72185626 ns/op	29607127 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      16	  79709510 ns/op	29601985 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      16	  72779459 ns/op	29601474 B/op	  400009 allocs/op
BenchmarkGetSubTree/total_time-8      	      15	  69887160 ns/op	29600968 B/op	  400009 allocs/op
PASS
ok  	git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree	25.032s
```

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-02-03 00:19:22 +03:00