func()

in perf-tools/scenarios/throughput.go [65:159]


func (ts *ThroughputScenario) Run(results *utils.Results) {
	scenarioResults := results.CreateScenarioResults(ts.GetName())
	schedulerNames := ts.scenarioConf.SchedulerNames
	maxWaitTime := time.Duration(ts.commonConf.MaxWaitSeconds) * time.Second
	var appManager framework.AppManager
	var appInfo *framework.AppInfo
	var appAnanyzer *framework.AppAnalyzer
	// make sure app is cleaned up when error occurred
	defer func() {
		CleanupApp(appManager, appInfo, maxWaitTime)
	}()

	for caseIndex, testCase := range ts.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.String("name", verGroupName),
			zap.String("description", verGroupDescription))
		// init app info & app manager
		requestInfos := ConvertToRequestInfos(testCase.RequestConfigs)
		appInfo = framework.NewAppInfo(ts.commonConf.Namespace, ThroughputScenarioName, ts.commonConf.Queue,
			requestInfos, ts.commonConf.PodTemplateSpec, ts.commonConf.PodSpec)
		appManager = framework.NewDeploymentsAppManager(ts.kubeClient)
		appAnanyzer = framework.NewAppAnalyzer(appInfo)

		// test for different schedulers
		cumulativeDistributions := make(map[string][]int, len(schedulerNames))
		for _, schedulerName := range schedulerNames {
			utils.Logger.Info("start testing for scheduler " + schedulerName)
			schedulerVerification := caseVerification.AddSubVerificationGroup(
				fmt.Sprintf("test for %s", schedulerName), verGroupDescription)

			// create app and wait for it to be running
			utils.Logger.Info("[Testing] create an app and wait for it to be running, refresh app 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))
				schedulerVerification.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)))

			// calculate scheduled time distribution and its cumulative distribution
			scheduledTimeDistribution := appAnanyzer.GetTimeDistribution(framework.PodScheduled)
			cumulativeDistributions[schedulerName] = getCumulativeDistribution(scheduledTimeDistribution)

			if ts.scenarioConf.CleanUpDelayMs > 0 {
				utils.Logger.Info("wait for a while before cleaning up test apps",
					zap.String("schedulerName", schedulerName),
					zap.Any("cleanUpDelayMs", ts.scenarioConf.CleanUpDelayMs))
				time.Sleep(time.Millisecond * time.Duration(ts.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))
				schedulerVerification.AddSubVerification("cleanup app", err.Error(), utils.FAILED)
				return
			}

			description := fmt.Sprintf("seconds: %d, throughputDistribution: %+v",
				len(scheduledTimeDistribution), scheduledTimeDistribution)
			schedulerVerification.AddSubVerification("get scheduled time distribution", description, utils.SUCCEEDED)
		}
		// draw chart
		linePoints := utils.GetLinePoints(cumulativeDistributions)
		chartFileName := fmt.Sprintf("%s-case%d-%d", ThroughputScenarioName,
			caseIndex, appInfo.GetDesiredNumTasks())
		chart := &utils.Chart{
			Title:      "Scheduling Throughput",
			XLabel:     "Seconds",
			YLabel:     "Number of Scheduled Pods",
			Width:      constants.ChartWidth,
			Height:     constants.ChartHeight,
			LinePoints: linePoints,
			SvgFile:    ts.commonConf.OutputPath + "/" + chartFileName + constants.ChartFileSuffix,
		}
		err := utils.DrawChart(chart)
		outputName := "output chart"
		if err != nil {
			caseVerification.AddSubVerification(outputName,
				fmt.Sprintf("failed to draw chart: %s", err.Error()),
				utils.FAILED)
			return
		}
		caseVerification.AddSubVerification(outputName, chart.SvgFile, utils.SUCCEEDED)
	}
}