From 2b91f2d61b42e838889135ad5daa081e6d9f9919 Mon Sep 17 00:00:00 2001 From: Zhigao Tong Date: Thu, 9 Feb 2023 14:38:38 +0800 Subject: [PATCH 1/2] finish Signed-off-by: Zhigao Tong --- planner/core/optimizer.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/planner/core/optimizer.go b/planner/core/optimizer.go index a5db249fd2be1..17d48d9d0b336 100644 --- a/planner/core/optimizer.go +++ b/planner/core/optimizer.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math" + "runtime" "strconv" "github.com/pingcap/errors" @@ -40,6 +41,7 @@ import ( "github.com/pingcap/tidb/types" utilhint "github.com/pingcap/tidb/util/hint" "github.com/pingcap/tidb/util/logutil" + "github.com/pingcap/tidb/util/mathutil" "github.com/pingcap/tidb/util/set" "github.com/pingcap/tidb/util/tracing" "github.com/pingcap/tipb/go-tipb" @@ -747,14 +749,19 @@ func calculateTiFlashStreamCountUsingMinLogicalCores(ctx context.Context, sctx s for _, row := range rows { if row[4].GetString() == "cpu-logical-cores" { logicalCpus, err := strconv.Atoi(row[5].GetString()) - if err == nil && logicalCpus > 0 && uint64(logicalCpus) < minLogicalCores { - minLogicalCores = uint64(logicalCpus) + if err == nil && logicalCpus > 0 { + minLogicalCores = mathutil.Min(minLogicalCores, uint64(logicalCpus)) } } } // No need to check len(serersInfo) == serverCount here, since missing some servers' info won't affect the correctness if minLogicalCores > 1 && minLogicalCores != initialMaxCores { - return true, minLogicalCores / 2 + if runtime.GOARCH == "amd64" { + // In most x86-64 platforms, `Thread(s) per core` is 2 + return true, minLogicalCores / 2 + } + // ARM cpus don't implement Hyper-threading + return true, minLogicalCores } return false, 0 From a87d99c985ddf9e47b2a0f63756cbb670d591f31 Mon Sep 17 00:00:00 2001 From: Zhigao Tong Date: Thu, 9 Feb 2023 14:41:58 +0800 Subject: [PATCH 2/2] 1 Signed-off-by: Zhigao Tong --- planner/core/optimizer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/planner/core/optimizer.go b/planner/core/optimizer.go index 17d48d9d0b336..bc298dbc404e0 100644 --- a/planner/core/optimizer.go +++ b/planner/core/optimizer.go @@ -760,8 +760,9 @@ func calculateTiFlashStreamCountUsingMinLogicalCores(ctx context.Context, sctx s // In most x86-64 platforms, `Thread(s) per core` is 2 return true, minLogicalCores / 2 } - // ARM cpus don't implement Hyper-threading + // ARM cpus don't implement Hyper-threading. return true, minLogicalCores + // Other platforms are too rare to consider } return false, 0