Browse Source

Add benchmarking for RPC & wire

pull/169/head
Jae Kwon 9 years ago
parent
commit
a62c7bfef1
2 changed files with 66 additions and 3 deletions
  1. +6
    -3
      benchmarks/simu/counter.go
  2. +60
    -0
      benchmarks/wire_test.go

+ 6
- 3
benchmarks/simu/counter.go View File

@ -22,22 +22,25 @@ func main() {
// Read a bunch of responses
go func() {
for {
res, ok := <-ws.ResultsCh
_, ok := <-ws.ResultsCh
if !ok {
break
}
fmt.Println("Received response", res)
//fmt.Println("Received response", string(wire.JSONBytes(res)))
}
}()
// Make a bunch of requests
request := rpctypes.NewRPCRequest("fakeid", "status", nil)
request := rpctypes.NewRPCRequest("fakeid", "net_info", nil)
for i := 0; ; i++ {
reqBytes := wire.JSONBytes(request)
err := ws.WriteMessage(websocket.TextMessage, reqBytes)
if err != nil {
Exit(err.Error())
}
if i%1000 == 0 {
fmt.Println(i)
}
}
ws.Stop()


+ 60
- 0
benchmarks/wire_test.go View File

@ -0,0 +1,60 @@
package benchmarks
import (
"testing"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-p2p"
"github.com/tendermint/go-wire"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
func BenchmarkEncodeStatus(b *testing.B) {
b.StopTimer()
pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519)
status := &ctypes.ResultStatus{
NodeInfo: &p2p.NodeInfo{
PubKey: pubKey,
Moniker: "SOMENAME",
Network: "SOMENAME",
RemoteAddr: "SOMEADDR",
ListenAddr: "SOMEADDR",
Version: "SOMEVER",
Other: []string{"SOMESTRING", "OTHERSTRING"},
},
PubKey: pubKey,
LatestBlockHash: []byte("SOMEBYTES"),
LatestBlockHeight: 123,
LatestBlockTime: 1234,
}
b.StartTimer()
counter := 0
for i := 0; i < b.N; i++ {
jsonBytes := wire.JSONBytes(status)
counter += len(jsonBytes)
}
}
func BenchmarkEncodeNodeInfo(b *testing.B) {
b.StopTimer()
pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519)
nodeInfo := &p2p.NodeInfo{
PubKey: pubKey,
Moniker: "SOMENAME",
Network: "SOMENAME",
RemoteAddr: "SOMEADDR",
ListenAddr: "SOMEADDR",
Version: "SOMEVER",
Other: []string{"SOMESTRING", "OTHERSTRING"},
}
b.StartTimer()
counter := 0
for i := 0; i < b.N; i++ {
jsonBytes := wire.JSONBytes(nodeInfo)
counter += len(jsonBytes)
}
}

Loading…
Cancel
Save