tendermint/benchmarks/simu/counter.go

56 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"encoding/binary"
"time"
//"encoding/hex"
"fmt"
"github.com/gorilla/websocket"
. "github.com/tendermint/go-common"
2016-01-12 13:54:27 -08:00
"github.com/tendermint/go-rpc/client"
"github.com/tendermint/go-rpc/types"
"github.com/tendermint/go-wire"
2016-01-02 16:23:29 -08:00
_ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types
)
func main() {
2016-02-18 18:11:50 -08:00
ws := rpcclient.NewWSClient("127.0.0.1:46657", "/websocket")
_, err := ws.Start()
if err != nil {
Exit(err.Error())
}
// Read a bunch of responses
go func() {
for {
2015-12-08 08:11:29 -08:00
_, ok := <-ws.ResultsCh
if !ok {
break
}
2015-12-08 08:11:29 -08:00
//fmt.Println("Received response", string(wire.JSONBytes(res)))
}
}()
// Make a bunch of requests
buf := make([]byte, 32)
for i := 0; ; i++ {
2016-01-25 14:34:08 -08:00
binary.BigEndian.PutUint64(buf, uint64(i))
//txBytes := hex.EncodeToString(buf[:n])
request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx", Arr(buf[:8]))
reqBytes := wire.JSONBytes(request)
2015-12-09 13:53:31 -08:00
//fmt.Println("!!", string(reqBytes))
fmt.Print(".")
err := ws.WriteMessage(websocket.TextMessage, reqBytes)
if err != nil {
Exit(err.Error())
}
2015-12-09 13:53:31 -08:00
if i%1000 == 0 {
2015-12-08 08:11:29 -08:00
fmt.Println(i)
}
2016-01-02 16:23:29 -08:00
time.Sleep(time.Microsecond * 1000)
}
ws.Stop()
}