Skip to content

Commit

Permalink
fix examples/cluster-restartgracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
cupen committed Dec 15, 2020
1 parent 7eaf22b commit f35fc72
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
21 changes: 16 additions & 5 deletions _examples/cluster-restartgracefully/Makefile
@@ -1,16 +1,19 @@
loops:=10000
clients:=10
cp:=consul
ttl:=10s
loops:=10000
clients:=10
interval:=0ms

start:
tmux new-session -d -s eg
tmux split-window -t "eg:0" -v
tmux split-window -t "eg:0.0" -h
tmux select-pane -t "eg:0.2"
tmux split-window -t "eg:0.0" -h -p 66
tmux split-window -t "eg:0.1" -h -p 50
tmux select-pane -t "eg:0.3"
tmux send-keys -t "eg:0.0" "go run server/main.go --provider $(cp) --ttl $(ttl) --port 8081" Enter
tmux send-keys -t "eg:0.1" "go run server/main.go --provider $(cp) --ttl $(ttl) --port 8082" Enter
tmux send-keys -t "eg:0.2" "sleep 3 && go run client/main.go --provider $(cp) --clients $(clients) --loops $(loops)" Enter
tmux send-keys -t "eg:0.2" "go run server/main.go --provider $(cp) --ttl $(ttl) --port 8083" Enter
tmux send-keys -t "eg:0.3" "sleep 3 && go run client/main.go --provider $(cp) --clients $(clients) --loops $(loops) --interval $(interval) " Enter
# tmux send-keys -t "eg:0.2" "go run member/main.go" Enter
tmux attach -t eg
tmux kill-session -t eg
Expand All @@ -20,6 +23,14 @@ start-with-etcd:
make start cp=etcd


mock-clients-10w:
make start cp=etcd clients=100000 loops=10 interval=100ms


mock-clients-20w:
make start cp=etcd clients=200000 loops=10 interval=100ms


stop:
tmux kill-session -t eg

Expand Down
9 changes: 6 additions & 3 deletions _examples/cluster-restartgracefully/client/main.go
Expand Up @@ -23,6 +23,7 @@ var (
)

func main() {
cluster.SetLogLevel(log.ErrorLevel)
var loops = flag.Int("loops", 10000, "request times.")
var interval = flag.Duration("interval", 0, "request interval miliseconds per client.")
var clients = flag.Int("clients", 1, "clients count.")
Expand Down Expand Up @@ -73,7 +74,7 @@ func startNode(port int, provider string) {

func runClientsAll(clients int, loops int, interval time.Duration) {
var wg sync.WaitGroup
now := time.Now()
var now = time.Now()
for i := 0; i < clients; i++ {
wg.Add(1)
grainId := fmt.Sprintf("client-%d", i)
Expand All @@ -83,10 +84,12 @@ func runClientsAll(clients int, loops int, interval time.Duration) {
}()
}
wg.Wait()
cost := time.Since(now)
plog.Info("end all.",
log.Int("clients", clients),
log.Int("loops", clients*loops),
log.Duration("take", time.Since(now)))
log.Int("total", clients*loops),
log.Int("req/s", clients*loops/int(cost/time.Second)),
log.Duration("take", cost))
}

func runClient(grainId string, loops int, interval time.Duration) {
Expand Down
7 changes: 7 additions & 0 deletions _examples/cluster-restartgracefully/go.mod
Expand Up @@ -7,7 +7,14 @@ replace github.com/AsynkronIT/protoactor-go => ../..
require (
github.com/AsynkronIT/goconsole v0.0.0-20160504192649-bfa12eebf716
github.com/AsynkronIT/protoactor-go v0.0.0-00010101000000-000000000000
github.com/cespare/xxhash v1.1.0 // indirect
github.com/coreos/etcd v3.3.25+incompatible // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-redis/redis v6.15.9+incompatible
github.com/gogo/protobuf v1.3.1
go.uber.org/zap v1.16.0 // indirect
google.golang.org/grpc v1.25.1
)
1 change: 1 addition & 0 deletions _examples/cluster-restartgracefully/server/main.go
Expand Up @@ -24,6 +24,7 @@ var (
)

func main() {
cluster.SetLogLevel(log.ErrorLevel)
var provider = flag.String("provider", "consul", "clients count.")
var actorTTL = flag.Duration("ttl", 10*time.Second, "time to live of actor.")
var port = flag.Int("port", 0, "listen port.")
Expand Down

0 comments on commit f35fc72

Please sign in to comment.