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

heartbeat: reduce unnecessary RunTask #8559

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 15 additions & 17 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,20 @@ func HandleOverlaps(ctx context.Context, c Cluster, overlaps []*core.RegionInfo)
}

// Collect collects the cluster information.
func Collect(ctx context.Context, c Cluster, region *core.RegionInfo, hasRegionStats bool) {
if hasRegionStats {
// get region again from root tree. make sure the observed region is the latest.
bc := c.GetBasicCluster()
if bc == nil {
return
}
region = bc.GetRegion(region.GetID())
if region == nil {
return
}
select {
case <-ctx.Done():
return
default:
}
c.GetRegionStats().Observe(region, c.GetBasicCluster().GetRegionStores(region))
func Collect(ctx context.Context, c Cluster, region *core.RegionInfo) {
// get region again from root tree. make sure the observed region is the latest.
bc := c.GetBasicCluster()
if bc == nil {
return
}
region = bc.GetRegion(region.GetID())
if region == nil {
return
}
select {
case <-ctx.Done():
return
default:
}
c.GetRegionStats().Observe(region, c.GetBasicCluster().GetRegionStores(region))
}
21 changes: 12 additions & 9 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c
regionID,
ratelimit.ObserveRegionStatsAsync,
func(ctx context.Context) {
cluster.Collect(ctx, c, region, hasRegionStats)
cluster.Collect(ctx, c, region)
},
)
}
Expand Down Expand Up @@ -679,14 +679,17 @@ func (c *Cluster) processRegionHeartbeat(ctx *core.MetaProcessContext, region *c
)
}
tracer.OnSaveCacheFinished()
// handle region stats
ctx.TaskRunner.RunTask(
regionID,
ratelimit.CollectRegionStatsAsync,
func(ctx context.Context) {
cluster.Collect(ctx, c, region, hasRegionStats)
},
)
if hasRegionStats {
// handle region stats
ctx.TaskRunner.RunTask(
regionID,
ratelimit.CollectRegionStatsAsync,
func(ctx context.Context) {
cluster.Collect(ctx, c, region)
},
)
}

tracer.OnCollectRegionStatsFinished()
return nil
}
Expand Down
26 changes: 14 additions & 12 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio
regionID,
ratelimit.ObserveRegionStatsAsync,
func(ctx context.Context) {
cluster.Collect(ctx, c, region, hasRegionStats)
cluster.Collect(ctx, c, region)
},
)
}
Expand Down Expand Up @@ -1119,17 +1119,19 @@ func (c *RaftCluster) processRegionHeartbeat(ctx *core.MetaProcessContext, regio
}

tracer.OnSaveCacheFinished()
// handle region stats
ctx.MiscRunner.RunTask(
regionID,
ratelimit.CollectRegionStatsAsync,
func(ctx context.Context) {
// TODO: Due to the accuracy requirements of the API "/regions/check/xxx",
// region stats needs to be collected in API mode.
// We need to think of a better way to reduce this part of the cost in the future.
cluster.Collect(ctx, c, region, hasRegionStats)
},
)
if hasRegionStats {
// handle region stats
ctx.MiscRunner.RunTask(
regionID,
ratelimit.CollectRegionStatsAsync,
func(ctx context.Context) {
// TODO: Due to the accuracy requirements of the API "/regions/check/xxx",
// region stats needs to be collected in API mode.
// We need to think of a better way to reduce this part of the cost in the future.
cluster.Collect(ctx, c, region)
},
)
}

tracer.OnCollectRegionStatsFinished()
if c.storage != nil {
Expand Down