github.com/evdatsion/aphelion-dpos-bft@v0.32.1/benchmarks/simu/counter.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"encoding/binary"
     6  	"fmt"
     7  	"time"
     8  
     9  	cmn "github.com/evdatsion/aphelion-dpos-bft/libs/common"
    10  	rpcclient "github.com/evdatsion/aphelion-dpos-bft/rpc/lib/client"
    11  )
    12  
    13  func main() {
    14  	wsc := rpcclient.NewWSClient("127.0.0.1:26657", "/websocket")
    15  	err := wsc.Start()
    16  	if err != nil {
    17  		cmn.Exit(err.Error())
    18  	}
    19  	defer wsc.Stop()
    20  
    21  	// Read a bunch of responses
    22  	go func() {
    23  		for {
    24  			_, ok := <-wsc.ResponsesCh
    25  			if !ok {
    26  				break
    27  			}
    28  			//fmt.Println("Received response", string(wire.JSONBytes(res)))
    29  		}
    30  	}()
    31  
    32  	// Make a bunch of requests
    33  	buf := make([]byte, 32)
    34  	for i := 0; ; i++ {
    35  		binary.BigEndian.PutUint64(buf, uint64(i))
    36  		//txBytes := hex.EncodeToString(buf[:n])
    37  		fmt.Print(".")
    38  		err = wsc.Call(context.TODO(), "broadcast_tx", map[string]interface{}{"tx": buf[:8]})
    39  		if err != nil {
    40  			cmn.Exit(err.Error())
    41  		}
    42  		if i%1000 == 0 {
    43  			fmt.Println(i)
    44  		}
    45  		time.Sleep(time.Microsecond * 1000)
    46  	}
    47  }