/
e2e_perf.go
253 lines (228 loc) · 9.65 KB
/
e2e_perf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scenarios
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/TaoYang526/goutils/pkg/profiling"
"github.com/apache/yunikorn-release/perf-tools/framework"
"github.com/apache/yunikorn-release/perf-tools/utils"
"go.uber.org/zap"
)
const E2EPerfScenarioName = "e2e_perf"
type E2EPerfScenario struct {
kubeClient *utils.KubeClient
commonConf *framework.CommonConfig
scenarioConf *E2EPerfScenarioConfig
}
type E2EPerfScenarioConfig struct {
CleanUpDelayMs int
ShowNumOfLastTasks int
Cases []*E2EPerfCaseConfig
}
type E2EPerfCaseConfig struct {
Description string
SchedulerName string
RequestConfigs []*RequestConfig
}
func init() {
framework.Register(&E2EPerfScenario{})
}
func (ts *E2EPerfScenario) GetName() string {
return E2EPerfScenarioName
}
func (ts *E2EPerfScenario) Init(kubeClient *utils.KubeClient, conf *framework.Config) error {
ts.kubeClient = kubeClient
ts.commonConf = conf.Common
ts.scenarioConf = &E2EPerfScenarioConfig{}
return LoadScenarioConf(conf, ts.GetName(), ts.scenarioConf)
}
func (eps *E2EPerfScenario) Run(results *utils.Results) {
scenarioResults := results.CreateScenarioResults(eps.GetName())
maxWaitTime := time.Duration(eps.commonConf.MaxWaitSeconds) * time.Second
var appManager framework.AppManager
var appInfo *framework.AppInfo
// make sure app is cleaned up when error occurred
defer func() {
CleanupApp(appManager, appInfo, maxWaitTime)
}()
for caseIndex, testCase := range eps.scenarioConf.Cases {
verGroupName := fmt.Sprintf("Case-%d", caseIndex)
verGroupDescription := fmt.Sprintf("%+v", testCase.Description)
caseVerification := scenarioResults.AddVerificationGroup(verGroupName, verGroupDescription)
utils.Logger.Info("[Prepare] add verification group",
zap.Int("caseIndex", caseIndex),
zap.String("name", verGroupName),
zap.String("description", verGroupDescription))
// init app info, app manager, app analyzer and node analyzer
requestInfos := ConvertToRequestInfos(testCase.RequestConfigs)
appInfo = framework.NewAppInfo(eps.commonConf.Namespace, E2EPerfScenarioName, eps.commonConf.Queue,
requestInfos, eps.commonConf.PodTemplateSpec, eps.commonConf.PodSpec)
appManager = framework.NewDeploymentsAppManager(eps.kubeClient)
appAnalyzer := framework.NewAppAnalyzer(appInfo)
nodeAnalyzer := framework.NewNodeAnalyzer(eps.kubeClient, eps.commonConf.NodeSelector)
schedulerName := testCase.SchedulerName
// prepare nodes
err := nodeAnalyzer.InitNodeInfosBeforeTesting()
if err != nil {
utils.Logger.Error("failed to init nodes", zap.Error(err))
caseVerification.AddSubVerification("init nodes", err.Error(), utils.FAILED)
return
}
utils.Logger.Info("[Prepare] init nodes", zap.Int("numNodes", len(nodeAnalyzer.GetAllocatableNodes())))
// create app and wait for it to be running
utils.Logger.Info("[Testing] create an app and wait for it to be running, refresh tasks status at last",
zap.String("appID", appInfo.AppID))
beginTime := time.Now().Truncate(time.Second)
err = appManager.CreateWaitAndRefreshTasksStatus(schedulerName, appInfo, maxWaitTime)
if err != nil {
utils.Logger.Error("failed to create/wait/refresh app", zap.Error(err))
caseVerification.AddSubVerification("test app", err.Error(), utils.FAILED)
return
}
utils.Logger.Info("all requirements of this app are satisfied",
zap.String("appID", appInfo.AppID),
zap.Duration("elapseTime", time.Since(beginTime)))
// fulfill nodes info after testing
nodeAnalyzer.AnalyzeApp(appInfo)
scheduledNodes := nodeAnalyzer.GetScheduledNodes()
utils.Logger.Info("got related nodes", zap.Int("numScheduledNodes", len(scheduledNodes)))
// analyze-1: print slow tasks (optional)
if eps.scenarioConf.ShowNumOfLastTasks > 0 {
slowTasksStatus := appAnalyzer.GetLastTasks(eps.scenarioConf.ShowNumOfLastTasks)
utils.Logger.Info(fmt.Sprintf("[Analyze] Show last %d tasks: ", len(slowTasksStatus)))
for _, task := range slowTasksStatus {
utils.Logger.Info("task status",
zap.String("taskID", task.TaskID),
zap.String("nodeID", task.NodeID),
zap.Duration("to-running-duration", task.RunningTime.Sub(task.CreateTime)),
zap.Time("createTime", task.CreateTime),
zap.Time("runningTime", task.RunningTime))
}
}
// analyze-2: print tasks distribution on nodes
tasksDistributionInfo := appAnalyzer.GetTasksDistributionInfo(scheduledNodes)
utils.Logger.Info("[Analyze] tasks distribution info on nodes",
zap.Int("LeastNum", tasksDistributionInfo.LeastNum),
zap.String("LeastNumNodeID", tasksDistributionInfo.LeastNumNodeID),
zap.Int("MostNum", tasksDistributionInfo.MostNum),
zap.String("MostNumNodeID", tasksDistributionInfo.MostNumNodeID),
zap.Float64("AvgNumPerNode", tasksDistributionInfo.AvgNum),
zap.Int("NumTasks", len(appInfo.TasksStatus)),
zap.Int("NumScheduledNodes", len(scheduledNodes)))
utils.Logger.Info("node with least number of tasks", zap.Any("summary",
tasksDistributionInfo.SortedNodeInfos[0].GetSummary()))
utils.Logger.Info("node with most number of tasks", zap.Any("summary",
tasksDistributionInfo.SortedNodeInfos[len(tasksDistributionInfo.SortedNodeInfos)-1].GetSummary()))
// profiling
prof := appAnalyzer.GetTasksProfiling()
if prof.GetCount() > 0 {
utils.Logger.Info("[Analyze] time statistics for pod conditions")
statsTableFilePath := fmt.Sprintf("%s/%s-case%d-timecost-stat.txt",
eps.commonConf.OutputPath, eps.GetName(), caseIndex)
statsOutputName := "time statistics"
stats := prof.GetTimeStatistics()
statsTable := ParseTableFromStatistic(stats)
if err := statsTable.Output(statsTableFilePath); err != nil {
caseVerification.AddSubVerification(statsOutputName,
fmt.Sprintf("failed to output %s: %s", statsOutputName, err.Error()),
utils.FAILED)
return
}
caseVerification.AddSubVerification(statsOutputName, statsTableFilePath, utils.SUCCEEDED)
statsTable.Print()
utils.Logger.Info("[Analyze] QPS statistics for pod conditions")
qpsStatsTableFilePath := fmt.Sprintf("%s/%s-case%d-qps-stat.txt",
eps.commonConf.OutputPath, eps.GetName(), caseIndex)
qpsStatsOutputName := "QPS statistics"
qpsStat, err := prof.GetQPSStatistics()
if err != nil {
caseVerification.AddSubVerification(qpsStatsOutputName,
fmt.Sprintf("failed to output %s: %s", qpsStatsOutputName, err.Error()),
utils.FAILED)
}
qpsStatsTable := ParseTableFromQPSStatistics(qpsStat, framework.GetOrderedTaskConditionTypes())
if err := qpsStatsTable.Output(qpsStatsTableFilePath); err != nil {
caseVerification.AddSubVerification(qpsStatsOutputName,
fmt.Sprintf("failed to output %s: %s", qpsStatsOutputName, err.Error()),
utils.FAILED)
return
}
caseVerification.AddSubVerification(qpsStatsOutputName, qpsStatsTableFilePath, utils.SUCCEEDED)
qpsStatsTable.Print()
}
if eps.scenarioConf.CleanUpDelayMs > 0 {
utils.Logger.Info("wait for a while before cleaning up test apps",
zap.String("schedulerName", schedulerName),
zap.Any("cleanUpDelayMs", eps.scenarioConf.CleanUpDelayMs))
time.Sleep(time.Millisecond * time.Duration(eps.scenarioConf.CleanUpDelayMs))
}
// delete this app and wait for it to be cleaned up
utils.Logger.Info("[Cleanup] delete this app then wait for it to be cleaned up",
zap.String("appID", appInfo.AppID))
err = appManager.DeleteWait(appInfo, maxWaitTime)
if err != nil {
utils.Logger.Error("failed to delete/wait app", zap.Error(err))
caseVerification.AddSubVerification("cleanup app", err.Error(), utils.FAILED)
return
}
}
}
func ParseTableFromStatistic(statistics *profiling.TimeStatistics) *utils.Table {
var data [][]string
for _, stat := range statistics.StagesTime {
rowData := []string{stat.From, stat.To, strconv.Itoa(stat.Count),
stat.TotalTime.String(), stat.AvgTime.String(),
fmt.Sprintf("%.2f", stat.Percentage)}
data = append(data, rowData)
}
return &utils.Table{
Headers: []string{"From", "To", "Count", "TotalTime", "AvgTime", "Percentage"},
Data: data,
}
}
func ParseTableFromQPSStatistics(statistics *profiling.QPSStatistics, orderedKeys []framework.TaskConditionType) *utils.Table {
var data [][]string
if len(orderedKeys) > 0 {
for _, key := range orderedKeys {
if stat := getStageQPS(statistics.StagesQPS, ")"+string(key)); stat != nil {
rowData := []string{stat.To, strconv.Itoa(stat.MaxQPS),
fmt.Sprintf("%.2f", stat.AvgQPS), fmt.Sprintf("%+v", stat.Samples)}
data = append(data, rowData)
}
}
} else {
for _, stat := range statistics.StagesQPS {
rowData := []string{stat.To, strconv.Itoa(stat.MaxQPS),
fmt.Sprintf("%.2f", stat.AvgQPS), fmt.Sprintf("%+v", stat.Samples)}
data = append(data, rowData)
}
}
return &utils.Table{
Headers: []string{"To", "MaxQPS", "AvgQPS", "Samples"},
Data: data,
}
}
func getStageQPS(qpsMap map[string]*profiling.StageQPS, suffix string) *profiling.StageQPS {
for key, item := range qpsMap {
if strings.HasSuffix(key, suffix) {
return item
}
}
return nil
}