Browse Source

Merge pull request #1964 from tendermint/dev/tmbench_improve_sendloop_efficiency

tools/tmbench: Improve accuracy with large tx sizes.
pull/1975/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
a1400aee73
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 481 deletions
  1. +0
    -334
      tools/tm-bench/Gopkg.lock
  2. +0
    -55
      tools/tm-bench/Gopkg.toml
  3. +1
    -67
      tools/tm-bench/Makefile
  4. +0
    -18
      tools/tm-bench/bench_test.go
  5. +24
    -7
      tools/tm-bench/transacter.go
  6. +104
    -0
      tools/tm-bench/transacter_test.go

+ 0
- 334
tools/tm-bench/Gopkg.lock View File

@ -1,334 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/beorn7/perks"
packages = ["quantile"]
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec"]
revision = "fdfc19097e7ac6b57035062056f5b7b4638b8898"
[[projects]]
name = "github.com/davecgh/go-spew"
packages = ["spew"]
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
branch = "master"
name = "github.com/ebuchman/fail-test"
packages = ["."]
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
[[projects]]
name = "github.com/go-kit/kit"
packages = [
"log",
"log/level",
"log/term",
"metrics",
"metrics/discard",
"metrics/internal/lv",
"metrics/prometheus"
]
revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
version = "v0.6.0"
[[projects]]
name = "github.com/go-logfmt/logfmt"
packages = ["."]
revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5"
version = "v0.3.0"
[[projects]]
name = "github.com/go-stack/stack"
packages = ["."]
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
version = "v1.7.0"
[[projects]]
name = "github.com/gogo/protobuf"
packages = [
"gogoproto",
"jsonpb",
"proto",
"protoc-gen-gogo/descriptor",
"sortkeys",
"types"
]
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
version = "v1.0.0"
[[projects]]
name = "github.com/golang/protobuf"
packages = [
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/timestamp"
]
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/golang/snappy"
packages = ["."]
revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"
[[projects]]
name = "github.com/gorilla/websocket"
packages = ["."]
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0"
[[projects]]
branch = "master"
name = "github.com/jmhodges/levigo"
packages = ["."]
revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9"
[[projects]]
branch = "master"
name = "github.com/kr/logfmt"
packages = ["."]
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
[[projects]]
name = "github.com/matttproud/golang_protobuf_extensions"
packages = ["pbutil"]
revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c"
version = "v1.0.1"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
branch = "master"
name = "github.com/prometheus/client_golang"
packages = [
"prometheus",
"prometheus/promhttp"
]
revision = "ee1c9d7e23df7f011bdf6f12a5c9e7f0ae10a1fe"
[[projects]]
branch = "master"
name = "github.com/prometheus/client_model"
packages = ["go"]
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
[[projects]]
branch = "master"
name = "github.com/prometheus/common"
packages = [
"expfmt",
"internal/bitbucket.org/ww/goautoneg",
"model"
]
revision = "7600349dcfe1abd18d72d3a1770870d9800a7801"
[[projects]]
branch = "master"
name = "github.com/prometheus/procfs"
packages = [
".",
"internal/util",
"nfs",
"xfs"
]
revision = "ae68e2d4c00fed4943b5f6698d504a5fe083da8a"
[[projects]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
packages = ["."]
revision = "e2704e165165ec55d062f5919b4b29494e9fa790"
[[projects]]
branch = "master"
name = "github.com/syndtr/goleveldb"
packages = [
"leveldb",
"leveldb/cache",
"leveldb/comparer",
"leveldb/errors",
"leveldb/filter",
"leveldb/iterator",
"leveldb/journal",
"leveldb/memdb",
"leveldb/opt",
"leveldb/storage",
"leveldb/table",
"leveldb/util"
]
revision = "c4c61651e9e37fa117f53c5a906d3b63090d8445"
[[projects]]
branch = "master"
name = "github.com/tendermint/ed25519"
packages = [
".",
"edwards25519",
"extra25519"
]
revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057"
[[projects]]
name = "github.com/tendermint/go-amino"
packages = ["."]
revision = "2106ca61d91029c931fd54968c2bb02dc96b1412"
version = "0.10.1"
[[projects]]
branch = "develop"
name = "github.com/tendermint/tendermint"
packages = [
"abci/client",
"abci/example/code",
"abci/example/kvstore",
"abci/types",
"blockchain",
"config",
"consensus",
"consensus/types",
"crypto",
"crypto/merkle",
"crypto/tmhash",
"evidence",
"libs/autofile",
"libs/clist",
"libs/common",
"libs/db",
"libs/events",
"libs/flowrate",
"libs/log",
"libs/pubsub",
"libs/pubsub/query",
"mempool",
"node",
"p2p",
"p2p/conn",
"p2p/pex",
"p2p/upnp",
"privval",
"proxy",
"rpc/client",
"rpc/core",
"rpc/core/types",
"rpc/grpc",
"rpc/lib",
"rpc/lib/client",
"rpc/lib/server",
"rpc/lib/types",
"state",
"state/txindex",
"state/txindex/kv",
"state/txindex/null",
"types",
"version"
]
revision = "f5ad8ef8600c33532a16de0879ff6b9745bb394d"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = [
"curve25519",
"internal/subtle",
"nacl/box",
"nacl/secretbox",
"openpgp/armor",
"openpgp/errors",
"poly1305",
"ripemd160",
"salsa20/salsa"
]
revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"context",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"netutil",
"trace"
]
revision = "039a4258aec0ad3c79b905677cceeab13b296a77"
[[projects]]
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable"
]
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
[[projects]]
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"codes",
"connectivity",
"credentials",
"encoding",
"encoding/proto",
"grpclb/grpc_lb_v1/messages",
"grpclog",
"internal",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"stats",
"status",
"tap",
"transport"
]
revision = "d11072e7ca9811b1100b80ca0269ac831f06d024"
version = "v1.11.3"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "5c21a60b80ac7d60f7be693de13f9fadb62226b502431bdb38fb9794a98c5b02"
solver-name = "gps-cdcl"
solver-version = 1

+ 0
- 55
tools/tm-bench/Gopkg.toml View File

@ -1,55 +0,0 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
name = "github.com/go-kit/kit"
version = "^0.6.0"
[[constraint]]
name = "github.com/gorilla/websocket"
version = "^1.2.0"
[[constraint]]
name = "github.com/pkg/errors"
version = "^0.8.0"
[[constraint]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
[[constraint]]
name = "github.com/tendermint/tendermint"
branch = "develop"
# this got updated and broke, so locked to an old working commit ...
[[override]]
name = "google.golang.org/genproto"
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
[prune]
go-tests = true
unused-packages = true

+ 1
- 67
tools/tm-bench/Makefile View File

@ -1,35 +1,7 @@
DIST_DIRS := find * -type d -exec
VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go)
GOTOOLS = \
github.com/mitchellh/gox \
github.com/golang/dep/cmd/dep \
gopkg.in/alecthomas/gometalinter.v2
all: check get_vendor_deps build test install metalinter
check: check_tools
########################################
### Tools & dependencies
check_tools:
@# https://stackoverflow.com/a/25668869
@echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
get_tools:
@echo "--> Installing tools"
go get -u -v $(GOTOOLS)
@gometalinter.v2 --install
update_tools:
@echo "--> Updating tools"
@go get -u $(GOTOOLS)
get_vendor_deps:
@rm -rf vendor/
@echo "--> Running dep ensure"
@dep ensure
all: build test install
########################################
### Build
@ -72,44 +44,6 @@ clean:
rm -f ./tm-bench
rm -rf ./dist
########################################
### Formatting, linting, and vetting
fmt:
@go fmt ./...
metalinter:
@echo "==> Running linter"
gometalinter.v2 --vendor --deadline=600s --disable-all \
--enable=maligned \
--enable=deadcode \
--enable=goconst \
--enable=goimports \
--enable=gosimple \
--enable=ineffassign \
--enable=megacheck \
--enable=misspell \
--enable=staticcheck \
--enable=safesql \
--enable=structcheck \
--enable=unconvert \
--enable=unused \
--enable=varcheck \
--enable=vetshadow \
./...
#--enable=gas \
#--enable=dupl \
#--enable=errcheck \
#--enable=gocyclo \
#--enable=golint \ <== comments on anything exported
#--enable=gotype \
#--enable=interfacer \
#--enable=unparam \
#--enable=vet \
metalinter_all:
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html


+ 0
- 18
tools/tm-bench/bench_test.go View File

@ -1,18 +0,0 @@
package main
import (
"testing"
"time"
)
func BenchmarkTimingPerTx(b *testing.B) {
startTime := time.Now()
endTime := startTime.Add(time.Second)
for i := 0; i < b.N; i++ {
if i%20 == 0 {
if time.Now().After(endTime) {
continue
}
}
}
}

+ 24
- 7
tools/tm-bench/transacter.go View File

@ -160,6 +160,11 @@ func (t *transacter) sendLoop(connIndex int) {
hostname = "127.0.0.1"
}
hostnameHash = md5.Sum([]byte(hostname))
// each transaction embeds connection index, tx number and hash of the hostname
// we update the tx number between successive txs
tx := generateTx(connIndex, txNumber, t.Size, hostnameHash)
txHex := make([]byte, len(tx)*2)
hex.Encode(txHex, tx)
for {
select {
@ -172,17 +177,18 @@ func (t *transacter) sendLoop(connIndex int) {
started = true
}
now := time.Now()
for i := 0; i < t.Rate; i++ {
// each transaction embeds connection index, tx number and hash of the hostname
tx := generateTx(connIndex, txNumber, t.Size, hostnameHash)
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
// update tx number of the tx, and the corresponding hex
updateTx(tx, txHex, txNumber)
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": txHex})
if err != nil {
fmt.Printf("failed to encode params: %v\n", err)
os.Exit(1)
}
rawParamsJSON := json.RawMessage(paramsJSON)
c.SetWriteDeadline(time.Now().Add(sendTimeout))
c.SetWriteDeadline(now.Add(sendTimeout))
err = c.WriteJSON(rpctypes.RPCRequest{
JSONRPC: "2.0",
ID: "tm-bench",
@ -197,9 +203,10 @@ func (t *transacter) sendLoop(connIndex int) {
return
}
// Time added here is 7.13 ns/op, not significant enough to worry about
if i%20 == 0 {
if time.Now().After(endTime) {
// cache the time.Now() reads to save time.
if i%5 == 0 {
now = time.Now()
if now.After(endTime) {
// Plus one accounts for sending this tx
numTxSent = i + 1
break
@ -265,3 +272,13 @@ func generateTx(connIndex int, txNumber int, txSize int, hostnameHash [md5.Size]
return tx
}
// warning, mutates input byte slice
func updateTx(tx []byte, txHex []byte, txNumber int) {
binary.PutUvarint(tx[8:16], uint64(txNumber))
hexUpdate := make([]byte, 16)
hex.Encode(hexUpdate, tx[8:16])
for i := 16; i < 32; i++ {
txHex[i] = hexUpdate[i-16]
}
}

+ 104
- 0
tools/tm-bench/transacter_test.go View File

@ -0,0 +1,104 @@
package main
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"testing"
"time"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)
// This test tests that the output of generate tx and update tx is consistent
func TestGenerateTxUpdateTxConsistentency(t *testing.T) {
cases := []struct {
connIndex int
startingTxNumber int
txSize int
hostname string
numTxsToTest int
}{
{0, 0, 50, "localhost:26657", 1000},
{70, 300, 10000, "localhost:26657", 1000},
{0, 50, 100000, "localhost:26657", 1000},
}
for tcIndex, tc := range cases {
hostnameHash := md5.Sum([]byte(tc.hostname))
// Tx generated from update tx. This is defined outside of the loop, since we have
// to a have something initially to update
updatedTx := generateTx(tc.connIndex, tc.startingTxNumber, tc.txSize, hostnameHash)
updatedHex := make([]byte, len(updatedTx)*2)
hex.Encode(updatedHex, updatedTx)
for i := 0; i < tc.numTxsToTest; i++ {
expectedTx := generateTx(tc.connIndex, tc.startingTxNumber+i, tc.txSize, hostnameHash)
expectedHex := make([]byte, len(expectedTx)*2)
hex.Encode(expectedHex, expectedTx)
updateTx(updatedTx, updatedHex, tc.startingTxNumber+i)
// after first 32 bytes is 8 bytes of time, then purely random bytes
require.Equal(t, expectedTx[:32], updatedTx[:32],
"First 32 bytes of the txs differed. tc #%d, i #%d", tcIndex, i)
require.Equal(t, expectedHex[:64], updatedHex[:64],
"First 64 bytes of the hex differed. tc #%d, i #%d", tcIndex, i)
// Test the lengths of the txs are as expected
require.Equal(t, tc.txSize, len(expectedTx),
"Length of expected Tx differed. tc #%d, i #%d", tcIndex, i)
require.Equal(t, tc.txSize, len(updatedTx),
"Length of expected Tx differed. tc #%d, i #%d", tcIndex, i)
require.Equal(t, tc.txSize*2, len(expectedHex),
"Length of expected hex differed. tc #%d, i #%d", tcIndex, i)
require.Equal(t, tc.txSize*2, len(updatedHex),
"Length of updated hex differed. tc #%d, i #%d", tcIndex, i)
}
}
}
func BenchmarkIterationOfSendLoop(b *testing.B) {
var (
connIndex = 0
txSize = 25000
)
now := time.Now()
// something too far away to matter
endTime := now.Add(time.Hour)
txNumber := 0
hostnameHash := md5.Sum([]byte{0})
tx := generateTx(connIndex, txNumber, txSize, hostnameHash)
txHex := make([]byte, len(tx)*2)
hex.Encode(txHex, tx)
b.ResetTimer()
for i := 0; i < b.N; i++ {
updateTx(tx, txHex, txNumber)
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": txHex})
if err != nil {
fmt.Printf("failed to encode params: %v\n", err)
os.Exit(1)
}
_ = json.RawMessage(paramsJSON)
_ = now.Add(sendTimeout)
if err != nil {
err = errors.Wrap(err,
fmt.Sprintf("txs send failed on connection #%d", connIndex))
logger.Error(err.Error())
return
}
// Cache the now operations
if i%5 == 0 {
now = time.Now()
if now.After(endTime) {
break
}
}
txNumber++
}
}

Loading…
Cancel
Save