Skip to content

Commit

Permalink
planner: fix calculating TiFlash stream count (#41221)
Browse files Browse the repository at this point in the history
ref #40123
  • Loading branch information
solotzg authored Feb 10, 2023
1 parent 95e660f commit 893cdb4
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit 893cdb4

Please sign in to comment.