tmbench: Make tx size configurable
* Make the parameter for tx size in bytes -s <size>, w/ default value 250
This commit is contained in:
parent
c3769b88e4
commit
b7925cd34f
|
@ -34,7 +34,7 @@ with the last command being in a seperate window.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
tm-bench [-c 1] [-T 10] [-r 1000] [endpoints]
|
tm-bench [-c 1] [-T 10] [-r 1000] [-s 250] [endpoints]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
tm-bench localhost:26657
|
tm-bench localhost:26657
|
||||||
|
@ -45,6 +45,8 @@ with the last command being in a seperate window.
|
||||||
Connections to keep open per endpoint (default 1)
|
Connections to keep open per endpoint (default 1)
|
||||||
-r int
|
-r int
|
||||||
Txs per second to send in a connection (default 1000)
|
Txs per second to send in a connection (default 1000)
|
||||||
|
-s int
|
||||||
|
Size per tx in bytes
|
||||||
-v Verbose output
|
-v Verbose output
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
|
@ -27,13 +27,14 @@ type statistics struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var duration, txsRate, connections int
|
var duration, txsRate, connections, txSize int
|
||||||
var verbose bool
|
var verbose bool
|
||||||
var outputFormat, broadcastTxMethod string
|
var outputFormat, broadcastTxMethod string
|
||||||
|
|
||||||
flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint")
|
flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint")
|
||||||
flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds")
|
flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds")
|
||||||
flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection")
|
flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection")
|
||||||
|
flag.IntVar(&txSize, "s", 250, "The size of a transaction in bytes.")
|
||||||
flag.StringVar(&outputFormat, "output-format", "plain", "Output format: plain or json")
|
flag.StringVar(&outputFormat, "output-format", "plain", "Output format: plain or json")
|
||||||
flag.StringVar(&broadcastTxMethod, "broadcast-tx-method", "async", "Broadcast method: async (no guarantees; fastest), sync (ensures tx is checked) or commit (ensures tx is checked and committed; slowest)")
|
flag.StringVar(&broadcastTxMethod, "broadcast-tx-method", "async", "Broadcast method: async (no guarantees; fastest), sync (ensures tx is checked) or commit (ensures tx is checked and committed; slowest)")
|
||||||
flag.BoolVar(&verbose, "v", false, "Verbose output")
|
flag.BoolVar(&verbose, "v", false, "Verbose output")
|
||||||
|
@ -101,6 +102,7 @@ Examples:
|
||||||
endpoints,
|
endpoints,
|
||||||
connections,
|
connections,
|
||||||
txsRate,
|
txsRate,
|
||||||
|
txSize,
|
||||||
"broadcast_tx_"+broadcastTxMethod,
|
"broadcast_tx_"+broadcastTxMethod,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -228,12 +230,13 @@ func startTransacters(
|
||||||
endpoints []string,
|
endpoints []string,
|
||||||
connections,
|
connections,
|
||||||
txsRate int,
|
txsRate int,
|
||||||
|
txSize int,
|
||||||
broadcastTxMethod string,
|
broadcastTxMethod string,
|
||||||
) []*transacter {
|
) []*transacter {
|
||||||
transacters := make([]*transacter, len(endpoints))
|
transacters := make([]*transacter, len(endpoints))
|
||||||
|
|
||||||
for i, e := range endpoints {
|
for i, e := range endpoints {
|
||||||
t := newTransacter(e, connections, txsRate, broadcastTxMethod)
|
t := newTransacter(e, connections, txsRate, txSize, broadcastTxMethod)
|
||||||
t.SetLogger(logger)
|
t.SetLogger(logger)
|
||||||
if err := t.Start(); err != nil {
|
if err := t.Start(); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
|
|
@ -25,14 +25,12 @@ const (
|
||||||
sendTimeout = 10 * time.Second
|
sendTimeout = 10 * time.Second
|
||||||
// see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313
|
// see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313
|
||||||
pingPeriod = (30 * 9 / 10) * time.Second
|
pingPeriod = (30 * 9 / 10) * time.Second
|
||||||
|
|
||||||
// the size of a transaction in bytes.
|
|
||||||
txSize = 250
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type transacter struct {
|
type transacter struct {
|
||||||
Target string
|
Target string
|
||||||
Rate int
|
Rate int
|
||||||
|
Size int
|
||||||
Connections int
|
Connections int
|
||||||
BroadcastTxMethod string
|
BroadcastTxMethod string
|
||||||
|
|
||||||
|
@ -43,10 +41,11 @@ type transacter struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTransacter(target string, connections, rate int, broadcastTxMethod string) *transacter {
|
func newTransacter(target string, connections, rate int, size int, broadcastTxMethod string) *transacter {
|
||||||
return &transacter{
|
return &transacter{
|
||||||
Target: target,
|
Target: target,
|
||||||
Rate: rate,
|
Rate: rate,
|
||||||
|
Size: size,
|
||||||
Connections: connections,
|
Connections: connections,
|
||||||
BroadcastTxMethod: broadcastTxMethod,
|
BroadcastTxMethod: broadcastTxMethod,
|
||||||
conns: make([]*websocket.Conn, connections),
|
conns: make([]*websocket.Conn, connections),
|
||||||
|
@ -152,7 +151,7 @@ func (t *transacter) sendLoop(connIndex int) {
|
||||||
|
|
||||||
for i := 0; i < t.Rate; i++ {
|
for i := 0; i < t.Rate; i++ {
|
||||||
// each transaction embeds connection index, tx number and hash of the hostname
|
// each transaction embeds connection index, tx number and hash of the hostname
|
||||||
tx := generateTx(connIndex, txNumber, hostnameHash)
|
tx := generateTx(connIndex, txNumber, t.Size, hostnameHash)
|
||||||
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
|
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to encode params: %v\n", err)
|
fmt.Printf("failed to encode params: %v\n", err)
|
||||||
|
@ -207,7 +206,7 @@ func connect(host string) (*websocket.Conn, *http.Response, error) {
|
||||||
return websocket.DefaultDialer.Dial(u.String(), nil)
|
return websocket.DefaultDialer.Dial(u.String(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTx(connIndex int, txNumber int, hostnameHash [md5.Size]byte) []byte {
|
func generateTx(connIndex int, txNumber int, txSize int, hostnameHash [md5.Size]byte) []byte {
|
||||||
tx := make([]byte, txSize)
|
tx := make([]byte, txSize)
|
||||||
|
|
||||||
binary.PutUvarint(tx[:8], uint64(connIndex))
|
binary.PutUvarint(tx[:8], uint64(connIndex))
|
||||||
|
|
Loading…
Reference in New Issue