Skip to content

Commit

Permalink
set MaxConcurrentStreams
Browse files Browse the repository at this point in the history
Signed-off-by: okJiang <[email protected]>
  • Loading branch information
okJiang committed Jan 6, 2025
1 parent 41919ad commit f9a16f4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

"github.com/tikv/pd/pkg/errs"
rm "github.com/tikv/pd/pkg/mcs/resourcemanager/server"
"github.com/tikv/pd/pkg/memory"
sc "github.com/tikv/pd/pkg/schedule/config"
"github.com/tikv/pd/pkg/utils/configutil"
"github.com/tikv/pd/pkg/utils/grpcutil"
Expand Down Expand Up @@ -243,6 +244,9 @@ const (
defaultGCTunerThreshold = 0.6
minGCTunerThreshold = 0
maxGCTunerThreshold = 0.9
// If concurrentStreams reaches 600k, the memory usage is about 40GB. To
// protect the server from OOM, we set the default concurrency to 10k per GB.
defaultConcurrencyPerGB = 10000

defaultWaitRegionSplitTimeout = 30 * time.Second
defaultCheckRegionSplitInterval = 50 * time.Millisecond
Expand Down Expand Up @@ -731,7 +735,13 @@ func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) {
cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(c.Logger, c.Logger.Core(), c.LogProps.Syncer)
cfg.EnableGRPCGateway = c.EnableGRPCGateway
cfg.Logger = "zap"
var err error

totalMem, err := memory.MemTotal()
if err != nil {
log.Warn("fail to get total memory", zap.Error(err))

Check warning on line 741 in server/config/config.go

View check run for this annotation

Codecov / codecov/patch

server/config/config.go#L741

Added line #L741 was not covered by tests
} else {
cfg.MaxConcurrentStreams = uint32(defaultConcurrencyPerGB * (totalMem/uint64(units.GiB) + 1))
}

cfg.ListenPeerUrls, err = parseUrls(c.PeerUrls)
if err != nil {
Expand Down

0 comments on commit f9a16f4

Please sign in to comment.