Browse Source

[tm-bench] refactor code

- set ID in RPCRequest
- rename get_deps to get_vendor_deps
pull/1943/head
Anton Kaliaev 7 years ago
parent
commit
989ff83c4c
No known key found for this signature in database GPG Key ID: 7B6881D965918214
6 changed files with 60 additions and 59 deletions
  1. +1
    -1
      tm-bench/Dockerfile.dev
  2. +2
    -2
      tm-bench/Makefile
  3. +28
    -18
      tm-bench/glide.lock
  4. +2
    -2
      tm-bench/glide.yaml
  5. +1
    -13
      tm-bench/main.go
  6. +26
    -23
      tm-bench/transacter.go

+ 1
- 1
tm-bench/Dockerfile.dev View File

@ -7,6 +7,6 @@ COPY Makefile /go/src/github.com/tendermint/tools/tm-bench/
COPY glide.yaml /go/src/github.com/tendermint/tools/tm-bench/
COPY glide.lock /go/src/github.com/tendermint/tools/tm-bench/
RUN make get_deps
RUN make get_vendor_deps
COPY . /go/src/github.com/tendermint/tools/tm-bench

+ 2
- 2
tm-bench/Makefile View File

@ -7,7 +7,7 @@ GOTOOLS = \
tools:
go get -v $(GOTOOLS)
get_deps: tools
get_vendor_deps: tools
glide install
build:
@ -44,4 +44,4 @@ clean:
rm -f ./tm-bench
rm -rf ./dist
.PHONY: tools get_deps build install test build-all dist clean build-docker
.PHONY: tools get_vendor_deps build install test build-all dist clean build-docker

+ 28
- 18
tm-bench/glide.lock View File

@ -1,22 +1,28 @@
hash: 87a19f23803b3b2d23693942bf43dc598e5475dc92b87cd6f534b2ce8d664602
updated: 2017-08-14T18:50:15.367518383Z
hash: d196c017846efa4f180164cea76c9a950f1d22989fdb157d3e7bb858b0f5a86d
updated: 2017-10-06T07:26:42.070129304Z
imports:
- name: github.com/btcsuite/btcd
version: fd081f5ae4bfe9430189ceff89606213d827c7bc
version: 4803a8291c92a1d2d41041b942a9a9e37deab065
subpackages:
- btcec
- name: github.com/go-kit/kit
version: bcc4b7720576e21b922974d4a4397f576ba7ef35
version: 4dc7be5d2d12881735283bcab7352178e190fc71
subpackages:
- log
- log/level
- log/term
- name: github.com/go-logfmt/logfmt
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
- name: github.com/go-playground/locales
version: 1e5f1161c6416a5ff48840eb8724a394e48cc534
subpackages:
- currency
- name: github.com/go-playground/universal-translator
version: 71201497bace774495daed26a3874fd339e0b538
- name: github.com/go-stack/stack
version: 817915b46b97fd7bb80e8ab6b69f01a53ac3eebf
- name: github.com/golang/protobuf
version: 1909bc2f63dc92bb931deace8b8312c4db72d12f
version: 130e6b02ab059e7b717a096f397c5b60111cae74
subpackages:
- proto
- ptypes
@ -24,15 +30,15 @@ imports:
- ptypes/duration
- ptypes/timestamp
- name: github.com/gorilla/websocket
version: a69d9f6de432e2c6b296a947d8a5ee88f68522cf
version: 4201258b820c74ac8e6922fc9e6b52f71fe46f8d
- name: github.com/kr/logfmt
version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0
- name: github.com/pkg/errors
version: c605e284fe17294bda444b34710735b29d1a9d90
version: 2b3a18b5f0fb6b4f9190549597d3f962c02bc5eb
- name: github.com/rcrowley/go-metrics
version: 1f30fe9094a513ce4c700b9a54458bbb0c96996c
- name: github.com/tendermint/abci
version: 864d1f80b36b440bde030a5c18d8ac3aa8c2949d
version: 191c4b6d176169ffc7f9972d490fa362a3b7d940
subpackages:
- client
- example/dummy
@ -43,13 +49,13 @@ imports:
- edwards25519
- extra25519
- name: github.com/tendermint/go-crypto
version: 95b7c9e09c49b91bfbb71bb63dd514eb55450f16
version: 311e8c1bf00fa5868daad4f8ea56dcad539182c0
- name: github.com/tendermint/go-wire
version: 5f88da3dbc1a72844e6dfaf274ce87f851d488eb
subpackages:
- data
- name: github.com/tendermint/tendermint
version: 2fd8496bc109d010c6c2e415604131b500550e37
version: 7682ad9a60162dd17fd6f61aeed7049a8635ac78
subpackages:
- config
- p2p
@ -59,7 +65,7 @@ imports:
- rpc/lib/types
- types
- name: github.com/tendermint/tmlibs
version: 7ce4da1eee6004d627e780c8fe91e96d9b99e459
version: 096dcb90e60aa00b748b3fe49a4b95e48ebf1e13
subpackages:
- common
- events
@ -67,12 +73,12 @@ imports:
- log
- merkle
- name: github.com/tendermint/tools
version: 4368c04d98487f4d733618ba7ac32933e8fb7d04
version: 213b11a6cad7b3c7fdedd2cc05b74e62b4f318b1
subpackages:
- tm-monitor/eventmeter
- tm-monitor/monitor
- name: golang.org/x/crypto
version: b176d7def5d71bdd214203491f89843ed217f420
version: 9419663f5a44be8b34ca85f08abc5fe1be11f8a3
subpackages:
- curve25519
- nacl/box
@ -83,7 +89,7 @@ imports:
- ripemd160
- salsa20/salsa
- name: golang.org/x/net
version: 1c05540f6879653db88113bc4a2b70aec4bd491f
version: a04bdaca5b32abe1c069418fb7088ae607de5bd0
subpackages:
- context
- http2
@ -93,31 +99,35 @@ imports:
- lex/httplex
- trace
- name: golang.org/x/text
version: e56139fd9c5bc7244c76116c68e500765bb6db6b
version: d82c1812e304abfeeabd31e995a115a2855bf642
subpackages:
- secure/bidirule
- transform
- unicode/bidi
- unicode/norm
- name: google.golang.org/genproto
version: 09f6ed296fc66555a25fe4ce95173148778dfa85
version: f676e0f3ac6395ff1a529ae59a6670878a8371a6
subpackages:
- googleapis/rpc/status
- name: google.golang.org/grpc
version: 43d1787a0c69bbee488da207f010368a8f4d980d
version: 5279edf262dc22329b1e53281ce9d55c0a998216
subpackages:
- balancer
- codes
- connectivity
- credentials
- grpclb/grpc_lb_v1
- grpclb/grpc_lb_v1/messages
- grpclog
- internal
- keepalive
- metadata
- naming
- peer
- resolver
- stats
- status
- tap
- transport
- name: gopkg.in/go-playground/validator.v9
version: a021b2ec9a8a8bb970f3f15bc42617cb520e8a64
testImports: []

+ 2
- 2
tm-bench/glide.yaml View File

@ -7,7 +7,7 @@ import:
- package: github.com/pkg/errors
- package: github.com/rcrowley/go-metrics
- package: github.com/tendermint/tendermint
version: 2fd8496bc109d010c6c2e415604131b500550e37
version: v0.11.0
subpackages:
- rpc/lib/types
- types
@ -15,6 +15,6 @@ import:
subpackages:
- log
- package: github.com/tendermint/tools
version: 4368c04d98487f4d733618ba7ac32933e8fb7d04
version: 213b11a6cad7b3c7fdedd2cc05b74e62b4f318b1
subpackages:
- tm-monitor/monitor

+ 1
- 13
tm-bench/main.go View File

@ -14,8 +14,6 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log"
"github.com/tendermint/tools/tm-monitor/monitor"
"math/rand"
"crypto/md5"
)
var version = "0.1.0"
@ -76,8 +74,6 @@ Examples:
blockCh := make(chan tmtypes.Header, 100)
blockLatencyCh := make(chan float64, 100)
rand.Seed(time.Now().Unix())
nodes := startNodes(endpoints, blockCh, blockLatencyCh)
transacters := startTransacters(endpoints, connections, txsRate)
@ -142,18 +138,10 @@ func startNodes(endpoints []string, blockCh chan<- tmtypes.Header, blockLatencyC
}
func startTransacters(endpoints []string, connections int, txsRate int) []*transacter {
var hostHash [16]byte
if hostName , err := os.Hostname(); err != nil {
hostHash = md5.Sum([]byte("127.0.0.1"))
} else {
hostHash = md5.Sum([]byte(hostName))
}
transacters := make([]*transacter, len(endpoints))
for i, e := range endpoints {
t := newTransacter(e, connections, txsRate, hostHash)
t := newTransacter(e, connections, txsRate)
t.SetLogger(logger)
if err := t.Start(); err != nil {
fmt.Println(err)


+ 26
- 23
tm-bench/transacter.go View File

@ -1,6 +1,7 @@
package main
import (
"crypto/md5"
"encoding/binary"
"encoding/hex"
"encoding/json"
@ -24,13 +25,15 @@ const (
sendTimeout = 10 * time.Second
// see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313
pingPeriod = (30 * 9 / 10) * time.Second
// the size of a transaction in bytes.
txSize = 250
)
type transacter struct {
Target string
Rate int
Connections int
HostHash [16]byte
conns []*websocket.Conn
wg sync.WaitGroup
@ -39,12 +42,11 @@ type transacter struct {
logger log.Logger
}
func newTransacter(target string, connections int, rate int, hosthash [16]byte) *transacter {
func newTransacter(target string, connections int, rate int) *transacter {
return &transacter{
Target: target,
Rate: rate,
Connections: connections,
HostHash: hosthash,
conns: make([]*websocket.Conn, connections),
logger: log.NewNopLogger(),
}
@ -60,6 +62,8 @@ func (t *transacter) SetLogger(l log.Logger) {
func (t *transacter) Start() error {
t.stopped = false
rand.Seed(time.Now().Unix())
for i := 0; i < t.Connections; i++ {
c, _, err := connect(t.Target)
if err != nil {
@ -131,14 +135,22 @@ func (t *transacter) sendLoop(connIndex int) {
t.wg.Done()
}()
// hash of the host name is a part of each tx
var hostnameHash [md5.Size]byte
hostname, err := os.Hostname()
if err != nil {
hostname = "127.0.0.1"
}
hostnameHash = md5.Sum([]byte(hostname))
for {
select {
case <-txsTicker.C:
startTime := time.Now()
for i := 0; i < t.Rate; i++ {
// each transaction embeds connection index and tx number
tx := generateTx(connIndex, txNumber, t.HostHash)
// each transaction embeds connection index, tx number and hash of the hostname
tx := generateTx(connIndex, txNumber, hostnameHash)
paramsJson, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
if err != nil {
fmt.Printf("failed to encode params: %v\n", err)
@ -149,7 +161,7 @@ func (t *transacter) sendLoop(connIndex int) {
c.SetWriteDeadline(time.Now().Add(sendTimeout))
err = c.WriteJSON(rpctypes.RPCRequest{
JSONRPC: "2.0",
ID: "",
ID: "tm-bench",
Method: "broadcast_tx_async",
Params: &rawParamsJson,
})
@ -191,27 +203,18 @@ func connect(host string) (*websocket.Conn, *http.Response, error) {
return websocket.DefaultDialer.Dial(u.String(), nil)
}
func generateTx(a int, b int, hosthash [16]byte) []byte {
// 250 byte transaction
tx := make([]byte, 250)
// 0-8 connection number
binary.PutUvarint(tx[:8], uint64(a))
func generateTx(connIndex int, txNumber int, hostnameHash [md5.Size]byte) []byte {
tx := make([]byte, txSize)
// 8-16 transaction number
binary.PutUvarint(tx[8:16], uint64(b))
// 16-32 hostname hash
for i:=0; i < 16 ; i++ {
tx[16+i] = hosthash[i]
}
// 32-40 current time
binary.PutUvarint(tx[:8], uint64(connIndex))
binary.PutUvarint(tx[8:16], uint64(txNumber))
copy(tx[16:32], hostnameHash[:16])
binary.PutUvarint(tx[32:40], uint64(time.Now().Unix()))
// 40- random data
// 40-* random data
if _, err := rand.Read(tx[40:]); err != nil {
panic(errors.Wrap(err, "failed to generate transaction"))
panic(errors.Wrap(err, "failed to read random bytes"))
}
return tx
}

Loading…
Cancel
Save