-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resourcemanger: create cpu/memory monitor
Signed-off-by: Weizhen Wang <[email protected]>
- Loading branch information
1 parent
acb8d46
commit 3491770
Showing
12 changed files
with
199 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "resourcemanage", | ||
srcs = ["rm.go"], | ||
importpath = "github.com/pingcap/tidb/resourcemanager", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//util", | ||
"//util/cpu", | ||
"//util/memory", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2022 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package resourcemanager | ||
|
||
import ( | ||
"time" | ||
|
||
tidbutil "github.com/pingcap/tidb/util" | ||
"github.com/pingcap/tidb/util/cpu" | ||
"github.com/pingcap/tidb/util/memory" | ||
) | ||
|
||
// GlobalResourceManager is a global resource manager | ||
var GlobalResourceManager = NewResourceManger() | ||
|
||
// ResourceManager is a resource manager | ||
type ResourceManager struct { | ||
cpuObserver *cpu.Observer | ||
exitCh chan struct{} | ||
wg tidbutil.WaitGroupWrapper | ||
} | ||
|
||
// NewResourceManger is to create a new resource manager | ||
func NewResourceManger() *ResourceManager { | ||
return &ResourceManager{ | ||
cpuObserver: cpu.NewCPUObserver(), | ||
exitCh: make(chan struct{}), | ||
} | ||
} | ||
|
||
// Start is to start resource manager | ||
func (r *ResourceManager) Start() { | ||
r.wg.Run(r.cpuObserver.Start) | ||
r.wg.Run(func() { | ||
readMemTricker := time.NewTicker(memory.ReadMemInterval) | ||
defer readMemTricker.Stop() | ||
for { | ||
select { | ||
case <-readMemTricker.C: | ||
memory.ForceReadMemStats() | ||
case <-r.exitCh: | ||
return | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// Stop is to stop resource manager | ||
func (r *ResourceManager) Stop() { | ||
r.cpuObserver.Stop() | ||
close(r.exitCh) | ||
r.wg.Done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters