|
| 1 | +// Copyright Antimetal, Inc. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a source available license that can be found in the |
| 4 | +// LICENSE file or at: |
| 5 | +// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt |
| 6 | + |
| 7 | +//go:build integration |
| 8 | + |
| 9 | +package hardwaregraph_test |
| 10 | + |
| 11 | +import ( |
| 12 | + "context" |
| 13 | + "testing" |
| 14 | + "time" |
| 15 | + |
| 16 | + hardwaregraph "github.com/antimetal/agent/internal/hardware/graph" |
| 17 | + "github.com/antimetal/agent/internal/hardware/types" |
| 18 | + "github.com/antimetal/agent/internal/resource/store" |
| 19 | + "github.com/antimetal/agent/pkg/performance" |
| 20 | + "github.com/go-logr/logr" |
| 21 | + "github.com/stretchr/testify/require" |
| 22 | +) |
| 23 | + |
| 24 | +// BenchmarkHardwareGraph_SmallVM benchmarks a small VM (2 vCPU, 4GB RAM) |
| 25 | +func BenchmarkHardwareGraph_SmallVM(b *testing.B) { |
| 26 | + snapshot := &types.Snapshot{ |
| 27 | + Timestamp: time.Now(), |
| 28 | + CPUInfo: &performance.CPUInfo{ |
| 29 | + VendorID: "GenuineIntel", |
| 30 | + ModelName: "Intel Xeon", |
| 31 | + PhysicalCores: 1, |
| 32 | + LogicalCores: 2, |
| 33 | + Cores: generateSingleSocketCPUCores(1, true), |
| 34 | + }, |
| 35 | + MemoryInfo: &performance.MemoryInfo{ |
| 36 | + TotalBytes: 4294967296, |
| 37 | + NUMAEnabled: false, |
| 38 | + }, |
| 39 | + DiskInfo: []*performance.DiskInfo{ |
| 40 | + {Device: "sda", SizeBytes: 53687091200}, |
| 41 | + }, |
| 42 | + NetworkInfo: []*performance.NetworkInfo{ |
| 43 | + {Interface: "eth0", Speed: 1000}, |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + benchmarkBuildFromSnapshot(b, snapshot) |
| 48 | +} |
| 49 | + |
| 50 | +// BenchmarkHardwareGraph_StandardServer benchmarks a standard server (8 CPU, 32GB RAM) |
| 51 | +func BenchmarkHardwareGraph_StandardServer(b *testing.B) { |
| 52 | + snapshot := &types.Snapshot{ |
| 53 | + Timestamp: time.Now(), |
| 54 | + CPUInfo: &performance.CPUInfo{ |
| 55 | + VendorID: "GenuineIntel", |
| 56 | + ModelName: "Intel Xeon", |
| 57 | + PhysicalCores: 4, |
| 58 | + LogicalCores: 8, |
| 59 | + Cores: generateSingleSocketCPUCores(4, true), |
| 60 | + }, |
| 61 | + MemoryInfo: &performance.MemoryInfo{ |
| 62 | + TotalBytes: 34359738368, |
| 63 | + NUMAEnabled: true, |
| 64 | + NUMANodes: []performance.NUMANode{ |
| 65 | + { |
| 66 | + NodeID: 0, |
| 67 | + TotalBytes: 34359738368, |
| 68 | + CPUs: []int32{0, 1, 2, 3, 4, 5, 6, 7}, |
| 69 | + Distances: []int32{10}, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + DiskInfo: []*performance.DiskInfo{ |
| 74 | + {Device: "nvme0n1", SizeBytes: 1000204886016}, |
| 75 | + {Device: "nvme1n1", SizeBytes: 1000204886016}, |
| 76 | + {Device: "sda", SizeBytes: 4000787030016}, |
| 77 | + {Device: "sdb", SizeBytes: 4000787030016}, |
| 78 | + }, |
| 79 | + NetworkInfo: []*performance.NetworkInfo{ |
| 80 | + {Interface: "eth0", Speed: 10000}, |
| 81 | + {Interface: "eth1", Speed: 10000}, |
| 82 | + }, |
| 83 | + } |
| 84 | + |
| 85 | + benchmarkBuildFromSnapshot(b, snapshot) |
| 86 | +} |
| 87 | + |
| 88 | +// BenchmarkHardwareGraph_LargeServer benchmarks a large server (32 CPU, 256GB RAM) |
| 89 | +func BenchmarkHardwareGraph_LargeServer(b *testing.B) { |
| 90 | + snapshot := &types.Snapshot{ |
| 91 | + Timestamp: time.Now(), |
| 92 | + CPUInfo: &performance.CPUInfo{ |
| 93 | + VendorID: "GenuineIntel", |
| 94 | + ModelName: "Intel Xeon Gold", |
| 95 | + PhysicalCores: 16, |
| 96 | + LogicalCores: 32, |
| 97 | + Cores: generateSingleSocketCPUCores(16, true), |
| 98 | + }, |
| 99 | + MemoryInfo: &performance.MemoryInfo{ |
| 100 | + TotalBytes: 274877906944, |
| 101 | + NUMAEnabled: true, |
| 102 | + NUMANodes: []performance.NUMANode{ |
| 103 | + { |
| 104 | + NodeID: 0, |
| 105 | + TotalBytes: 137438953472, |
| 106 | + CPUs: []int32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, |
| 107 | + Distances: []int32{10, 21}, |
| 108 | + }, |
| 109 | + { |
| 110 | + NodeID: 1, |
| 111 | + TotalBytes: 137438953472, |
| 112 | + CPUs: []int32{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, |
| 113 | + Distances: []int32{21, 10}, |
| 114 | + }, |
| 115 | + }, |
| 116 | + }, |
| 117 | + DiskInfo: generateLargeServerDisks(8), |
| 118 | + NetworkInfo: []*performance.NetworkInfo{ |
| 119 | + {Interface: "eth0", Speed: 25000}, |
| 120 | + {Interface: "eth1", Speed: 25000}, |
| 121 | + {Interface: "eth2", Speed: 10000}, |
| 122 | + {Interface: "eth3", Speed: 10000}, |
| 123 | + }, |
| 124 | + } |
| 125 | + |
| 126 | + benchmarkBuildFromSnapshot(b, snapshot) |
| 127 | +} |
| 128 | + |
| 129 | +// BenchmarkHardwareGraph_NUMAServer benchmarks a multi-socket NUMA server |
| 130 | +func BenchmarkHardwareGraph_NUMAServer(b *testing.B) { |
| 131 | + snapshot := &types.Snapshot{ |
| 132 | + Timestamp: time.Now(), |
| 133 | + CPUInfo: &performance.CPUInfo{ |
| 134 | + VendorID: "GenuineIntel", |
| 135 | + ModelName: "Intel Xeon Platinum", |
| 136 | + PhysicalCores: 40, |
| 137 | + LogicalCores: 80, |
| 138 | + Cores: generateMultiSocketCPUCores(2, 20, true), |
| 139 | + }, |
| 140 | + MemoryInfo: &performance.MemoryInfo{ |
| 141 | + TotalBytes: 536870912000, |
| 142 | + NUMAEnabled: true, |
| 143 | + NUMANodes: generateNUMANodes(2, 20), |
| 144 | + }, |
| 145 | + DiskInfo: generateServerDiskConfig(), |
| 146 | + NetworkInfo: generateServerNetworkConfig(), |
| 147 | + } |
| 148 | + |
| 149 | + benchmarkBuildFromSnapshot(b, snapshot) |
| 150 | +} |
| 151 | + |
| 152 | +// BenchmarkHardwareGraph_ManyDisks benchmarks a storage server with many disks |
| 153 | +func BenchmarkHardwareGraph_ManyDisks(b *testing.B) { |
| 154 | + snapshot := &types.Snapshot{ |
| 155 | + Timestamp: time.Now(), |
| 156 | + CPUInfo: &performance.CPUInfo{ |
| 157 | + VendorID: "GenuineIntel", |
| 158 | + ModelName: "Intel Xeon", |
| 159 | + PhysicalCores: 8, |
| 160 | + LogicalCores: 16, |
| 161 | + Cores: generateSingleSocketCPUCores(8, true), |
| 162 | + }, |
| 163 | + MemoryInfo: &performance.MemoryInfo{ |
| 164 | + TotalBytes: 68719476736, |
| 165 | + NUMAEnabled: false, |
| 166 | + }, |
| 167 | + DiskInfo: generateLargeServerDisks(24), |
| 168 | + NetworkInfo: generateServerNetworkConfig(), |
| 169 | + } |
| 170 | + |
| 171 | + benchmarkBuildFromSnapshot(b, snapshot) |
| 172 | +} |
| 173 | + |
| 174 | +// BenchmarkHardwareGraph_ManyNetworkInterfaces benchmarks many network interfaces |
| 175 | +func BenchmarkHardwareGraph_ManyNetworkInterfaces(b *testing.B) { |
| 176 | + snapshot := &types.Snapshot{ |
| 177 | + Timestamp: time.Now(), |
| 178 | + CPUInfo: &performance.CPUInfo{ |
| 179 | + VendorID: "GenuineIntel", |
| 180 | + ModelName: "Intel Xeon", |
| 181 | + PhysicalCores: 8, |
| 182 | + LogicalCores: 16, |
| 183 | + Cores: generateSingleSocketCPUCores(8, true), |
| 184 | + }, |
| 185 | + MemoryInfo: &performance.MemoryInfo{ |
| 186 | + TotalBytes: 68719476736, |
| 187 | + NUMAEnabled: false, |
| 188 | + }, |
| 189 | + DiskInfo: generateServerDiskConfig(), |
| 190 | + NetworkInfo: generateManyNetworkInterfaces(50), |
| 191 | + } |
| 192 | + |
| 193 | + benchmarkBuildFromSnapshot(b, snapshot) |
| 194 | +} |
| 195 | + |
| 196 | +// Helper function to run the benchmark |
| 197 | +func benchmarkBuildFromSnapshot(b *testing.B, snapshot *types.Snapshot) { |
| 198 | + ctx := context.Background() |
| 199 | + logger := logr.Discard() |
| 200 | + |
| 201 | + b.ResetTimer() |
| 202 | + for i := 0; i < b.N; i++ { |
| 203 | + b.StopTimer() |
| 204 | + testStore, err := store.New(store.WithDataDir("")) |
| 205 | + require.NoError(b, err) |
| 206 | + builder := hardwaregraph.NewBuilder(logger, testStore) |
| 207 | + b.StartTimer() |
| 208 | + |
| 209 | + err = builder.BuildFromSnapshot(ctx, snapshot) |
| 210 | + require.NoError(b, err) |
| 211 | + |
| 212 | + b.StopTimer() |
| 213 | + testStore.Close() |
| 214 | + b.StartTimer() |
| 215 | + } |
| 216 | +} |
0 commit comments