forked from TrueCloudLab/frostfs-sdk-go
[#227] netmap: Do not use intermediate types for placement
Support preprocessing within the `NodeInfo` type. Provide methods for placement directly from the `NodeInfo` type. Returns slice of slices of `NodeInfo` from placement methods of `Netmap`. Remove no longer needed `Node` and `Nodes` types. ``` name old time/op new time/op delta ManySelects-12 19.7µs ±14% 15.8µs ±15% -19.70% (p=0.000 n=20+20) name old alloc/op new alloc/op delta ManySelects-12 8.65kB ± 0% 6.22kB ± 0% -28.03% (p=0.000 n=20+20) name old allocs/op new allocs/op delta ManySelects-12 82.0 ± 0% 81.0 ± 0% -1.22% (p=0.000 n=20+20) ``` Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2b21146185
commit
723ba5ee45
12 changed files with 305 additions and 246 deletions
|
@ -26,7 +26,7 @@ type TestCase struct {
|
|||
}
|
||||
}
|
||||
|
||||
func compareNodes(t testing.TB, expected [][]int, nodes Nodes, actual []Nodes) {
|
||||
func compareNodes(t testing.TB, expected [][]int, nodes nodes, actual [][]NodeInfo) {
|
||||
require.Equal(t, len(expected), len(actual))
|
||||
for i := range expected {
|
||||
require.Equal(t, len(expected[i]), len(actual[i]))
|
||||
|
@ -56,9 +56,8 @@ func TestPlacementPolicy_Interopability(t *testing.T) {
|
|||
copy(srcNodes, tc.Nodes)
|
||||
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
nodes := NodesFromInfo(tc.Nodes)
|
||||
nm, err := NewNetmap(nodes)
|
||||
require.NoError(t, err)
|
||||
var nm Netmap
|
||||
nm.SetNodes(tc.Nodes)
|
||||
|
||||
for name, tt := range tc.Tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
@ -70,13 +69,12 @@ func TestPlacementPolicy_Interopability(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, srcNodes, tc.Nodes)
|
||||
|
||||
res := v.Replicas()
|
||||
compareNodes(t, tt.Result, nodes, res)
|
||||
compareNodes(t, tt.Result, tc.Nodes, v)
|
||||
|
||||
if tt.Placement.Result != nil {
|
||||
res, err := nm.GetPlacementVectors(v, tt.Placement.Pivot)
|
||||
require.NoError(t, err)
|
||||
compareNodes(t, tt.Placement.Result, nodes, res)
|
||||
compareNodes(t, tt.Placement.Result, tc.Nodes, res)
|
||||
require.Equal(t, srcNodes, tc.Nodes)
|
||||
}
|
||||
}
|
||||
|
@ -103,8 +101,8 @@ func BenchmarkPlacementPolicyInteropability(b *testing.B) {
|
|||
require.NoError(b, json.Unmarshal(bs, &tc), "cannot unmarshal %s", ds[i].Name())
|
||||
|
||||
b.Run(tc.Name, func(b *testing.B) {
|
||||
nodes := NodesFromInfo(tc.Nodes)
|
||||
nm, err := NewNetmap(nodes)
|
||||
var nm Netmap
|
||||
nm.SetNodes(tc.Nodes)
|
||||
require.NoError(b, err)
|
||||
|
||||
for name, tt := range tc.Tests {
|
||||
|
@ -121,15 +119,14 @@ func BenchmarkPlacementPolicyInteropability(b *testing.B) {
|
|||
} else {
|
||||
require.NoError(b, err)
|
||||
|
||||
res := v.Replicas()
|
||||
compareNodes(b, tt.Result, nodes, res)
|
||||
compareNodes(b, tt.Result, tc.Nodes, v)
|
||||
|
||||
if tt.Placement.Result != nil {
|
||||
b.StartTimer()
|
||||
res, err := nm.GetPlacementVectors(v, tt.Placement.Pivot)
|
||||
b.StopTimer()
|
||||
require.NoError(b, err)
|
||||
compareNodes(b, tt.Placement.Result, nodes, res)
|
||||
compareNodes(b, tt.Placement.Result, tc.Nodes, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,9 +146,8 @@ func BenchmarkManySelects(b *testing.B) {
|
|||
tt, ok := tc.Tests["Select"]
|
||||
require.True(b, ok)
|
||||
|
||||
nodes := NodesFromInfo(tc.Nodes)
|
||||
nm, err := NewNetmap(nodes)
|
||||
require.NoError(b, err)
|
||||
var nm Netmap
|
||||
nm.SetNodes(tc.Nodes)
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue