Skip to content

Commit

Permalink
improve: get cpu number in container (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonfan authored Jan 11, 2022
1 parent d9af3b7 commit eedc4e2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
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

0 comments on commit eedc4e2

Please sign in to comment.