From 0f3e1f90cb3c5e3694c637900a1cc732c08572f7 Mon Sep 17 00:00:00 2001 From: Hu# Date: Thu, 23 May 2024 10:08:47 +0800 Subject: [PATCH 1/2] tools/ut: add a parallel parameter (#8186) ref tikv/pd#7969 add parallel parameter Signed-off-by: husharp --- tools/pd-ut/ut.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index 7781ab4ee3b..fbf2a640651 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -95,8 +95,7 @@ var ( var ( // runtime - p int - buildParallel int + parallel int workDir string coverFileTempDir string // arguments @@ -108,6 +107,7 @@ var ( func main() { race = handleFlag("--race") + parallelStr := stripFlag("--parallel") junitFile = stripFlag("--junitfile") coverProfile = stripFlag("--coverprofile") ignoreDir = stripFlag("--ignore") @@ -122,11 +122,21 @@ func main() { defer os.RemoveAll(coverFileTempDir) } - // Get the correct count of CPU if it's in docker. - p = runtime.GOMAXPROCS(0) - // We use 2 * p for `go build` to make it faster. - buildParallel = p * 2 var err error + procs := runtime.GOMAXPROCS(0) + if parallelStr == "" { + // Get the correct count of CPU if it's in docker. + parallel = procs + } else { + parallel, err = strconv.Atoi(parallelStr) + if err != nil { + fmt.Println("parse parallel error", err) + return + } + if parallel > procs { + fmt.Printf("Recommend to set parallel be same as the GOMAXPROCS=%d\n", procs) + } + } workDir, err = os.Getwd() if err != nil { fmt.Println("os.Getwd() error", err) @@ -353,12 +363,12 @@ func cmdRun(args ...string) bool { } } - fmt.Printf("building task finish, parallelism=%d, count=%d, takes=%v\n", buildParallel, len(tasks), time.Since(start)) + fmt.Printf("building task finish, parallelism=%d, count=%d, takes=%v\n", parallel*2, len(tasks), time.Since(start)) taskCh := make(chan task, 100) - works := make([]numa, p) + works := make([]numa, parallel) var wg sync.WaitGroup - for i := 0; i < p; i++ { + for i := 0; i < parallel; i++ { wg.Add(1) go works[i].worker(&wg, taskCh) } @@ -400,7 +410,7 @@ func cmdRun(args ...string) bool { // stripFlag strip the '--flag xxx' from the command line os.Args // Example of the os.Args changes -// Before: ut run pkg TestXXX --coverprofile xxx --junitfile yyy +// Before: ut run pkg TestXXX --coverprofile xxx --junitfile yyy --parallel 16 // After: ut run pkg TestXXX // The value of the flag is returned. func stripFlag(flag string) string { @@ -636,7 +646,7 @@ func (*numa) testCommand(pkg string, fn string) *exec.Cmd { args = append(args, "-test.coverprofile", tmpFile) } if strings.Contains(fn, "Suite") { - args = append(args, "-test.cpu", fmt.Sprint(p/2)) + args = append(args, "-test.cpu", fmt.Sprint(parallel/2)) } else { args = append(args, "-test.cpu", "1") } @@ -705,7 +715,8 @@ func buildTestBinaryMulti(pkgs []string) error { packages = append(packages, path.Join(modulePath, pkg)) } - p := strconv.Itoa(buildParallel) + // We use 2 * parallel for `go build` to make it faster. + p := strconv.Itoa(parallel * 2) cmd := exec.Command("go", "test", "-p", p, "--exec", xprogPath, "-vet", "off", "--tags=tso_function_test,deadlock") if coverProfile != "" { coverpkg := "./..." From 6b8d22779efd2fa1496c62a834691cf6f1d963a2 Mon Sep 17 00:00:00 2001 From: ShuNing Date: Thu, 23 May 2024 10:53:46 +0800 Subject: [PATCH 2/2] metrics: fix the duplicate avg metrics (#8210) ref tikv/pd#7897 metrics: fix the duplicate avg metrics Signed-off-by: nolouch Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- metrics/grafana/pd.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/grafana/pd.json b/metrics/grafana/pd.json index a2c3d31a4b0..69afb93f531 100644 --- a/metrics/grafana/pd.json +++ b/metrics/grafana/pd.json @@ -11248,7 +11248,7 @@ }, { "exemplar": true, - "expr": "rate(pd_scheduler_handle_region_heartbeat_duration_seconds_sum{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m]) / rate(pd_scheduler_handle_region_heartbeat_duration_seconds_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m])", + "expr": "sum(rate(pd_scheduler_handle_region_heartbeat_duration_seconds_sum{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m])) / sum(rate(pd_scheduler_handle_region_heartbeat_duration_seconds_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", store=~\"$store\"}[1m]))", "hide": false, "interval": "", "legendFormat": "avg",