github.com/renegr87/renegr87@v2.1.1+incompatible/core/ledger/kvledger/benchmark/experiments/conf.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package experiments
     8  
     9  import (
    10  	"flag"
    11  
    12  	"github.com/hyperledger/fabric/core/ledger/kvledger/benchmark/chainmgmt"
    13  )
    14  
    15  // txConf captures the transaction related configurations
    16  // numTotalTxs specifies the total transactions that should be executed and committed across chains
    17  // numParallelTxsPerChain specifies the parallel transactions on each of the chains
    18  // numWritesPerTx specifies the number of keys to write in each transaction
    19  // numReadsPerTx specifies the number of keys to read in each transaction, Note:  this parameters
    20  //   match the numWritesPerTx for normal benchmarks.  This can be set to zero to make batch update measurements.
    21  type txConf struct {
    22  	numTotalTxs            int
    23  	numParallelTxsPerChain int
    24  	numWritesPerTx         int
    25  	numReadsPerTx          int
    26  }
    27  
    28  // dataConf captures the data related configurations
    29  // numKVs specifies number of total key-values across chains
    30  // kvSize specifies the size of a key-value (in bytes)
    31  // useJSON specifies if the value stored is in JSON format
    32  type dataConf struct {
    33  	numKVs  int
    34  	kvSize  int
    35  	useJSON bool
    36  }
    37  
    38  // configuration captures all the configurations for an experiment
    39  // For details of individual configuration, see comments on the specific type
    40  type configuration struct {
    41  	chainMgrConf *chainmgmt.ChainMgrConf
    42  	batchConf    *chainmgmt.BatchConf
    43  	dataConf     *dataConf
    44  	txConf       *txConf
    45  }
    46  
    47  // emptyConf returns a an empty configuration (with nested structure only)
    48  func emptyConf() *configuration {
    49  	conf := &configuration{}
    50  	conf.chainMgrConf = &chainmgmt.ChainMgrConf{}
    51  	conf.batchConf = &chainmgmt.BatchConf{}
    52  	conf.txConf = &txConf{}
    53  	conf.dataConf = &dataConf{}
    54  	return conf
    55  }
    56  
    57  // confFromTestParams consumes the parameters passed by an experiment
    58  // and returns the configuration loaded with the parsed param values
    59  func confFromTestParams(testParams []string) *configuration {
    60  	conf := emptyConf()
    61  	flags := flag.NewFlagSet("testParams", flag.ExitOnError)
    62  
    63  	// chainMgrConf
    64  	dataDir := flags.String("DataDir", conf.chainMgrConf.DataDir, "Dir for ledger data")
    65  	numChains := flags.Int("NumChains", conf.chainMgrConf.NumChains, "Number of chains")
    66  
    67  	// txConf
    68  	numParallelTxsPerChain := flags.Int("NumParallelTxPerChain",
    69  		conf.txConf.numParallelTxsPerChain, "Number of TxSimulators concurrently on each chain")
    70  
    71  	numTotalTxs := flags.Int("NumTotalTx",
    72  		conf.txConf.numTotalTxs, "Number of total transactions")
    73  
    74  	numWritesPerTx := flags.Int("NumWritesPerTx",
    75  		conf.txConf.numWritesPerTx, "number of keys written in each Tx")
    76  
    77  	numReadsPerTx := flags.Int("NumReadsPerTx",
    78  		conf.txConf.numReadsPerTx, "number of keys to read in each Tx")
    79  
    80  	// batchConf
    81  	batchSize := flags.Int("BatchSize",
    82  		conf.batchConf.BatchSize, "number of Txs in each batch")
    83  
    84  	// dataConf
    85  	numKVs := flags.Int("NumKVs",
    86  		conf.dataConf.numKVs, "the keys are named as key_0, key_1,... upto key_(NumKVs-1)")
    87  
    88  	kvSize := flags.Int("KVSize",
    89  		conf.dataConf.kvSize, "size of the key-value in bytes")
    90  
    91  	useJSON := flags.Bool("UseJSONFormat", conf.dataConf.useJSON, "should CouchDB use JSON for values")
    92  
    93  	flags.Parse(testParams)
    94  
    95  	conf.chainMgrConf.DataDir = *dataDir
    96  	conf.chainMgrConf.NumChains = *numChains
    97  	conf.txConf.numParallelTxsPerChain = *numParallelTxsPerChain
    98  	conf.txConf.numTotalTxs = *numTotalTxs
    99  	conf.txConf.numWritesPerTx = *numWritesPerTx
   100  	conf.txConf.numReadsPerTx = *numReadsPerTx
   101  	conf.batchConf.BatchSize = *batchSize
   102  	conf.dataConf.numKVs = *numKVs
   103  	conf.dataConf.kvSize = *kvSize
   104  	conf.dataConf.useJSON = *useJSON
   105  	return conf
   106  }