Skip to content

Commit

Permalink
resourcemanger: create cpu monitor (#39962)
Browse files Browse the repository at this point in the history
ref #39657
  • Loading branch information
hawkingrei authored Dec 16, 2022
1 parent 97a9e63 commit 53572f8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
6 changes: 4 additions & 2 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@
"util/": "util code",
"parser/": "parser code",
"meta/": "parser code",
"extension/": "extension code"
"extension/": "extension code",
"resourcemanager/": "resourcemanager code"
}
},
"shift": {
Expand Down Expand Up @@ -765,7 +766,8 @@
"server/conn.go": "server/conn.go",
"server/conn_stmt.go": "server/conn_stmt.go",
"server/conn_test.go": "server/conn_test.go",
"extension/": "extension code"
"extension/": "extension code",
"resourcemanager/": "resourcemanager code"
}
},
"SA2000": {
Expand Down
12 changes: 12 additions & 0 deletions resourcemanager/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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",
],
)
47 changes: 47 additions & 0 deletions resourcemanager/rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 (
tidbutil "github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/cpu"
)

// GlobalResourceManager is a global resource manager
var GlobalResourceManager = NewResourceManger()

// ResourceManager is a resource manager
type ResourceManager struct {
cpuObserver *cpu.Observer
wg tidbutil.WaitGroupWrapper
}

// NewResourceManger is to create a new resource manager
func NewResourceManger() *ResourceManager {
return &ResourceManager{
cpuObserver: cpu.NewCPUObserver(),
}
}

// Start is to start resource manager
func (r *ResourceManager) Start() {
r.wg.Run(r.cpuObserver.Start)
}

// Stop is to stop resource manager
func (r *ResourceManager) Stop() {
r.cpuObserver.Stop()
r.wg.Done()
}
1 change: 1 addition & 0 deletions tidb-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"//planner/core",
"//plugin",
"//privilege/privileges",
"//resourcemanager:resourcemanage",
"//server",
"//session",
"//session/txninfo",
Expand Down
3 changes: 3 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/plugin"
"github.com/pingcap/tidb/privilege/privileges"
"github.com/pingcap/tidb/resourcemanager"
"github.com/pingcap/tidb/server"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/session/txninfo"
Expand Down Expand Up @@ -210,6 +211,7 @@ func main() {
printInfo()
setupBinlogClient()
setupMetrics()
resourcemanager.GlobalResourceManager.Start()
storage, dom := createStoreAndDomain()
svr := createServer(storage, dom)

Expand All @@ -223,6 +225,7 @@ func main() {
svr.Close()
cleanup(svr, storage, dom, graceful)
cpuprofile.StopCPUProfiler()
resourcemanager.GlobalResourceManager.Stop()
close(exited)
})
topsql.SetupTopSQL()
Expand Down

0 comments on commit 53572f8

Please sign in to comment.