Skip to content

Commit 5057a9d

Browse files
authored
add benchmark testing for UpdateContainerEnergyByTrainedPowerModel (#533)
Signed-off-by: Sam Yuan <[email protected]>
1 parent 92cee15 commit 5057a9d

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

pkg/model/benchmark_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package model_test
17+
18+
import (
19+
"strconv"
20+
"testing"
21+
22+
collector_metric "github.com/sustainable-computing-io/kepler/pkg/collector/metric"
23+
"github.com/sustainable-computing-io/kepler/pkg/config"
24+
"github.com/sustainable-computing-io/kepler/pkg/model"
25+
)
26+
27+
func benchmarkNtesting(b *testing.B, continerNumber int) {
28+
containersMetrics := map[string]*collector_metric.ContainerMetrics{}
29+
collector_metric.ContainerMetricNames = []string{config.CoreUsageMetric}
30+
b.ReportAllocs()
31+
for n := 0; n < continerNumber; n++ {
32+
containersMetrics["container"+strconv.Itoa(n)] = collector_metric.NewContainerMetrics("container"+strconv.Itoa(n), "podA", "test")
33+
containersMetrics["container"+strconv.Itoa(n)].CounterStats[config.CoreUsageMetric] = &collector_metric.UInt64Stat{}
34+
_ = containersMetrics["container"+strconv.Itoa(n)].CounterStats[config.CoreUsageMetric].AddNewDelta(100)
35+
}
36+
b.ResetTimer()
37+
model.UpdateContainerEnergyByTrainedPowerModel(containersMetrics)
38+
b.StopTimer()
39+
}
40+
41+
func BenchmarkUpdateContainerEnergyByTrainedPowerModelWith1000Contianer(b *testing.B) {
42+
benchmarkNtesting(b, 1000)
43+
}
44+
45+
func BenchmarkUpdateContainerEnergyByTrainedPowerModelWith2000Contianer(b *testing.B) {
46+
benchmarkNtesting(b, 2000)
47+
}
48+
49+
func BenchmarkUpdateContainerEnergyByTrainedPowerModelWith5000Contianer(b *testing.B) {
50+
benchmarkNtesting(b, 5000)
51+
}
52+
53+
func BenchmarkUpdateContainerEnergyByTrainedPowerModelWith10000Contianer(b *testing.B) {
54+
benchmarkNtesting(b, 10000)
55+
}

pkg/model/container_power.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ func UpdateContainerEnergy(containersMetrics map[string]*collector_metric.Contai
7979
if components.IsSystemCollectionSupported() {
8080
local.UpdateContainerEnergyByRatioPowerModel(containersMetrics, nodeMetrics)
8181
} else {
82-
updateContainerEnergyByTrainedPowerModel(containersMetrics)
82+
UpdateContainerEnergyByTrainedPowerModel(containersMetrics)
8383
}
8484
}
8585

86-
func updateContainerEnergyByTrainedPowerModel(containersMetrics map[string]*collector_metric.ContainerMetrics) {
86+
func UpdateContainerEnergyByTrainedPowerModel(containersMetrics map[string]*collector_metric.ContainerMetrics) {
8787
var enabled bool
8888
// convert the container metrics map to an array since the model server does not receive structured data
8989
// TODO: send data to model server via protobuf instead of no structured data

0 commit comments

Comments
 (0)