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

improve: get cpu number in container #340

Merged
merged 1 commit into from
Jan 11, 2022
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
3 changes: 2 additions & 1 deletion cmd/pixiu/pixiu.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

import (
gxruntime "github.com/dubbogo/gost/runtime"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -145,7 +146,7 @@ func initLimitCpus() error {
return err
}
if limitCpuNumber <= 0 {
runtime.GOMAXPROCS(runtime.NumCPU())
runtime.GOMAXPROCS(gxruntime.GetCPUNum())
} else {
runtime.GOMAXPROCS(int(limitCpuNumber))
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/apache/dubbo-go-hessian2 v1.10.0
github.com/creasty/defaults v1.5.2
github.com/dubbogo/dubbo-go-pixiu-filter v0.1.4
github.com/dubbogo/go-zookeeper v1.0.3
github.com/dubbogo/gost v1.11.20-0.20211116110728-26777ca61b4a
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5
github.com/dubbogo/gost v1.11.22
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gin-gonic/gin v1.7.4
github.com/go-playground/assert/v2 v2.0.1
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 h1:D21IyuvjDCshj1/qq+pCNd3VZOAEI9jy6Bi131YlXgI=
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40 h1:xvUo53O5MRZhVMJAxWCJcS5HHrqAiAG9SJ1LpMu6aAI=
Expand Down Expand Up @@ -188,14 +189,16 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZ
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dubbogo/dubbo-go-pixiu-filter v0.1.4 h1:R7SZYqn+trTQNehpZIOy+ywG2UjkvjJ+FlcPdVjPzXE=
github.com/dubbogo/dubbo-go-pixiu-filter v0.1.4/go.mod h1:d6SDK5BHl/QCvg84BN+g6LZS9QzVqnI2+yw0NBu0uac=
github.com/dubbogo/go-zookeeper v1.0.3 h1:UkuY+rBsxdT7Bs63QAzp9z7XqQ53W1j8E5rwl83me8g=
github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 h1:XoR8SSVziXe698dt4uZYDfsmHpKLemqAgFyndQsq5Kw=
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.11.11/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.12/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.18/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.20-0.20211116110728-26777ca61b4a h1:RLUCy1Rftro4EmUmqWQCdofwgo9mzPbrZ6d6xWgZNwo=
github.com/dubbogo/gost v1.11.20-0.20211116110728-26777ca61b4a/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.22 h1:7g1CCzq5PlnB2JothjWjVCoZ7ZVtPbwR+ijaEGPtdRk=
github.com/dubbogo/gost v1.11.22/go.mod h1:PhJ8+qZJx+Txjx1KthNPuVkCvUca0jRLgKWj/noGgeI=
github.com/dubbogo/grpc-go v1.42.6-triple h1:NDTATpffyaAkwC+GBk3SDB45eeMTdvZhJKkkX4nIKHs=
github.com/dubbogo/grpc-go v1.42.6-triple/go.mod h1:F1T9hnUvYGW4JLK1QNriavpOkhusU677ovPzLkk6zHM=
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
Expand Down
42 changes: 19 additions & 23 deletions pkg/adapter/dubboregistry/remoting/zookeeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ZooKeeperClient struct {
exit chan struct{}
Wait sync.WaitGroup

eventRegistry map[string][]*chan struct{}
eventRegistry map[string][]chan zk.Event
eventRegistryLock sync.RWMutex
}

Expand All @@ -84,7 +84,7 @@ func NewZooKeeperClient(name string, zkAddrs []string, timeout time.Duration) (*
ZkAddrs: zkAddrs,
Timeout: timeout,
exit: make(chan struct{}),
eventRegistry: make(map[string][]*chan struct{}),
eventRegistry: make(map[string][]chan zk.Event),
}
// connect to zookeeper
z.conn, event, err = zk.Connect(zkAddrs, timeout)
Expand All @@ -95,7 +95,7 @@ func NewZooKeeperClient(name string, zkAddrs []string, timeout time.Duration) (*
return z, event, nil
}

// StateToString translate the state to string
// StateToString will transfer zk state to string
func StateToString(state zk.State) string {
switch state {
case zk.StateDisconnected:
Expand All @@ -113,13 +113,9 @@ func StateToString(state zk.State) string {
case zk.StateConnected:
return "zookeeper connected"
case zk.StateHasSession:
return "zookeeper has session"
return "zookeeper has Session"
case zk.StateUnknown:
return "zookeeper unknown state"
case zk.State(zk.EventNodeDeleted):
return "zookeeper node deleted"
case zk.State(zk.EventNodeDataChanged):
return "zookeeper node data changed"
default:
return state.String()
}
Expand Down Expand Up @@ -150,7 +146,7 @@ func (z *ZooKeeperClient) ExistW(zkPath string) (<-chan zk.Event, error) {
func (z *ZooKeeperClient) HandleZkEvent(s <-chan zk.Event) {
var (
state int
e zk.Event
event zk.Event
)

defer func() {
Expand All @@ -162,40 +158,40 @@ func (z *ZooKeeperClient) HandleZkEvent(s <-chan zk.Event) {
select {
case <-z.exit:
return
case e = <-s:
case event = <-s:
logger.Infof("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}",
z.name, e.Type, e.Server, e.Path, e.State, StateToString(e.State), e.Err)
switch (int)(e.State) {
case (int)(zk.StateDisconnected):
z.name, event.Type, event.Server, event.Path, event.State, StateToString(event.State), event.Err)
switch event.State {
case zk.StateDisconnected:
logger.Warnf("zk{addr:%s} state is StateDisconnected, so close the zk client{name:%s}.", z.ZkAddrs, z.name)
z.Destroy()
return
case (int)(zk.EventNodeDataChanged), (int)(zk.EventNodeChildrenChanged):
logger.Infof("zkClient{%s} get zk node changed event{path:%s}", z.name, e.Path)
case zk.StateConnected:
logger.Infof("zkClient{%s} get zk node changed event{path:%s}", z.name, event.Path)
z.eventRegistryLock.RLock()
for p, a := range z.eventRegistry {
if strings.HasPrefix(p, e.Path) {
for path, a := range z.eventRegistry {
if strings.HasPrefix(event.Path, path) {
logger.Infof("send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener",
e.Path, p)
event.Path, path)
for _, e := range a {
*e <- struct{}{}
e <- event
}
}
}
z.eventRegistryLock.RUnlock()
case (int)(zk.StateConnecting), (int)(zk.StateConnected), (int)(zk.StateHasSession):
case zk.StateConnecting, zk.StateHasSession:
if state == (int)(zk.StateHasSession) {
continue
}
z.eventRegistryLock.RLock()
if a, ok := z.eventRegistry[e.Path]; ok && 0 < len(a) {
if a, ok := z.eventRegistry[event.Path]; ok && 0 < len(a) {
for _, e := range a {
*e <- struct{}{}
e <- event
}
}
z.eventRegistryLock.RUnlock()
}
state = (int)(e.State)
state = (int)(event.State)
}
}
}
Expand Down