Skip to content

Commit

Permalink
[FAB-5949] add the progress for the broadcast_msg
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
asaningmaxchain committed Oct 5, 2017
1 parent 297d393 commit edd8323
Show file tree
Hide file tree
Showing 24 changed files with 2,682 additions and 3 deletions.
15 changes: 12 additions & 3 deletions orderer/sample_clients/broadcast_msg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"golang.org/x/net/context"
"google.golang.org/grpc"
"gopkg.in/cheggaaa/pb.v1"
)

type broadcastClient struct {
Expand Down Expand Up @@ -72,6 +73,7 @@ func main() {
var messages uint64
var goroutines uint64
var msgSize uint64
var bar *pb.ProgressBar

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

msgData := make([]byte, msgSize)

var wg sync.WaitGroup
wg.Add(int(goroutines))
for i := uint64(0); i < goroutines; i++ {
go func(i uint64) {
go func(i uint64, pb *pb.ProgressBar) {
client, err := ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO())
if err != nil {
fmt.Println("Error connecting:", err)
Expand All @@ -112,6 +118,9 @@ func main() {
go func() {
for i := uint64(0); i < msgsPerGo; i++ {
err = s.getAck()
if err == nil && bar != nil {
bar.Increment()
}
}
if err != nil {
fmt.Printf("\nError: %v\n", err)
Expand All @@ -126,9 +135,9 @@ func main() {
<-done
wg.Done()
client.CloseSend()
fmt.Println("Go routine", i, "exiting")
}(i)
}(i, bar)
}

wg.Wait()
bar.FinishPrint("----------------------broadcast message finish-------------------------------")
}
21 changes: 21 additions & 0 deletions vendor/github.com/mattn/go-runewidth/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/mattn/go-runewidth/README.mkd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit edd8323

Please sign in to comment.