mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 15:22:15 +00:00
Add benchmarking for RPC & wire
This commit is contained in:
parent
53f74d052f
commit
a62c7bfef1
@ -22,22 +22,25 @@ func main() {
|
|||||||
// Read a bunch of responses
|
// Read a bunch of responses
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
res, ok := <-ws.ResultsCh
|
_, ok := <-ws.ResultsCh
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fmt.Println("Received response", res)
|
//fmt.Println("Received response", string(wire.JSONBytes(res)))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Make a bunch of requests
|
// Make a bunch of requests
|
||||||
request := rpctypes.NewRPCRequest("fakeid", "status", nil)
|
request := rpctypes.NewRPCRequest("fakeid", "net_info", nil)
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
reqBytes := wire.JSONBytes(request)
|
reqBytes := wire.JSONBytes(request)
|
||||||
err := ws.WriteMessage(websocket.TextMessage, reqBytes)
|
err := ws.WriteMessage(websocket.TextMessage, reqBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
Exit(err.Error())
|
||||||
}
|
}
|
||||||
|
if i%1000 == 0 {
|
||||||
|
fmt.Println(i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.Stop()
|
ws.Stop()
|
||||||
|
60
benchmarks/wire_test.go
Normal file
60
benchmarks/wire_test.go
Normal 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…
x
Reference in New Issue
Block a user