mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
chore: simplify linux nocgroup logic (#3949)
This commit is contained in:
parent
a7363f0c21
commit
5263805b3b
@ -1,5 +1,3 @@
|
||||
//go:build !nocgroup
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
@ -25,6 +23,7 @@ var (
|
||||
preTotal uint64
|
||||
limit float64
|
||||
cores uint64
|
||||
noCgroup bool
|
||||
initOnce sync.Once
|
||||
)
|
||||
|
||||
@ -32,6 +31,7 @@ var (
|
||||
func initialize() {
|
||||
cpus, err := effectiveCpus()
|
||||
if err != nil {
|
||||
noCgroup = true
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
@ -47,12 +47,14 @@ func initialize() {
|
||||
|
||||
preSystem, err = systemCpuUsage()
|
||||
if err != nil {
|
||||
noCgroup = true
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
preTotal, err = cpuUsage()
|
||||
if err != nil {
|
||||
noCgroup = true
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
@ -62,6 +64,10 @@ func initialize() {
|
||||
func RefreshCpu() uint64 {
|
||||
initOnce.Do(initialize)
|
||||
|
||||
if noCgroup {
|
||||
return 0
|
||||
}
|
||||
|
||||
total, err := cpuUsage()
|
||||
if err != nil {
|
||||
return 0
|
||||
|
@ -1,4 +1,4 @@
|
||||
//go:build !linux || nocgroup
|
||||
//go:build !linux
|
||||
|
||||
package internal
|
||||
|
||||
|
@ -141,7 +141,6 @@ func (s statement) QueryRowsPartialCtx(ctx context.Context, v any, args ...any)
|
||||
func (s statement) queryRows(ctx context.Context, scanFn func(any, rowsScanner) error,
|
||||
v any, args ...any) error {
|
||||
var scanFailed bool
|
||||
|
||||
err := s.brk.DoWithAcceptable(func() error {
|
||||
return queryStmt(ctx, s.stmt, func(rows *sql.Rows) error {
|
||||
err := scanFn(v, rows)
|
||||
|
@ -307,8 +307,8 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
|
||||
## 10. CNCF 云原生技术全景图
|
||||
|
||||
<p float="left">
|
||||
<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>
|
||||
<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-landscape-logo.svg" width="150"/>
|
||||
</p>
|
||||
|
||||
go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape.cncf.io/?selected=go-zero)。
|
||||
|
@ -248,8 +248,8 @@ Join the chat via https://discord.gg/4JQvC5A4Fe
|
||||
## Cloud Native Landscape
|
||||
|
||||
<p float="left">
|
||||
<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>
|
||||
<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>
|
||||
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-landscape-logo.svg" width="150"/>
|
||||
</p>
|
||||
|
||||
go-zero enlisted in the [CNCF Cloud Native Landscape](https://landscape.cncf.io/?selected=go-zero).
|
||||
|
Loading…
Reference in New Issue
Block a user