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

grpc: set MaxConcurrentStreams to avoid sudden traffic spikes that lead to PD OOM #8977

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 @@

"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 @@
defaultGCTunerThreshold = 0.6
minGCTunerThreshold = 0
maxGCTunerThreshold = 0.9
// If concurrentStreams reaches 600k, the memory usage is about 40GB. To
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any tests to support the conclusion?

Copy link
Member Author

@okJiang okJiang Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conclusion comes from a practical case where the cluster contains millions of regions. And its requests are ScanRegions mainly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMIIW, it only limits the concurrency for one connection, not total concurrency on the server side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In simple terms, should we consider this sudden surge in traffic as an anomaly? If so, I think we can set this parameter to protect PD. Do you know in what normal circumstances PD would experience such high traffic? For example, 16GB PD and 160k requests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/etcd-io/etcd/blob/fce823ac2830033270f8fe03fa1b56e62bf882b8/server/embed/config.go#L230-L232

// MaxConcurrentStreams specifies the maximum number of concurrent
// streams that each client can open at a time.

If users make massive requests using multiple clients, we have no way to limit it...

// 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 @@
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
Loading