Skip to content

Commit edd8323

Browse files
[FAB-5949] add the progress for the broadcast_msg
The broadcast_msg tool may send thousands or millions of messages, but there is no feedback to the console about progress.This CR vendors the BSD 3-clause licensed cheggaaa/pb library to display a progress bar in the console Change-Id: I3ac6e70ff704ff14b4860b4abe0a0f0a43af98cb Signed-off-by: liu minhan <cxa13241930467@163.com>
1 parent 297d393 commit edd8323

24 files changed

+2682
-3
lines changed

orderer/sample_clients/broadcast_msg/client.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"golang.org/x/net/context"
2525
"google.golang.org/grpc"
26+
"gopkg.in/cheggaaa/pb.v1"
2627
)
2728

2829
type broadcastClient struct {
@@ -72,6 +73,7 @@ func main() {
7273
var messages uint64
7374
var goroutines uint64
7475
var msgSize uint64
76+
var bar *pb.ProgressBar
7577

7678
flag.StringVar(&serverAddr, "server", fmt.Sprintf("%s:%d", config.General.ListenAddress, config.General.ListenPort), "The RPC server to connect to.")
7779
flag.StringVar(&channelID, "channelID", provisional.TestChainID, "The channel ID to broadcast to.")
@@ -94,13 +96,17 @@ func main() {
9496
if roundMsgs != messages {
9597
fmt.Println("Rounding messages to", roundMsgs)
9698
}
99+
bar = pb.New64(int64(roundMsgs))
100+
bar.ShowPercent = true
101+
bar.ShowSpeed = true
102+
bar = bar.Start()
97103

98104
msgData := make([]byte, msgSize)
99105

100106
var wg sync.WaitGroup
101107
wg.Add(int(goroutines))
102108
for i := uint64(0); i < goroutines; i++ {
103-
go func(i uint64) {
109+
go func(i uint64, pb *pb.ProgressBar) {
104110
client, err := ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO())
105111
if err != nil {
106112
fmt.Println("Error connecting:", err)
@@ -112,6 +118,9 @@ func main() {
112118
go func() {
113119
for i := uint64(0); i < msgsPerGo; i++ {
114120
err = s.getAck()
121+
if err == nil && bar != nil {
122+
bar.Increment()
123+
}
115124
}
116125
if err != nil {
117126
fmt.Printf("\nError: %v\n", err)
@@ -126,9 +135,9 @@ func main() {
126135
<-done
127136
wg.Done()
128137
client.CloseSend()
129-
fmt.Println("Go routine", i, "exiting")
130-
}(i)
138+
}(i, bar)
131139
}
132140

133141
wg.Wait()
142+
bar.FinishPrint("----------------------broadcast message finish-------------------------------")
134143
}

vendor/github.com/mattn/go-runewidth/LICENSE

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/mattn/go-runewidth/README.mkd

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)