Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix calculating TiFlash stream count #41221

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions planner/core/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math"
"runtime"
"strconv"

"github.com/pingcap/errors"
Expand All @@ -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"
Expand Down Expand Up @@ -747,14 +749,20 @@ 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
// Other platforms are too rare to consider
}

return false, 0
Expand Down