github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/tools/LTE/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/test/tools/LTE/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 // numKeysInEachTx specifies the number of keys that each of transactions should operate 19 type txConf struct { 20 numTotalTxs int 21 numParallelTxsPerChain int 22 numKeysInEachTx int 23 } 24 25 // dataConf captures the data related configurations 26 // numKVs specifies number of total key-values across chains 27 // kvSize specifies the size of a key-value (in bytes) 28 type dataConf struct { 29 numKVs int 30 kvSize int 31 } 32 33 // configuration captures all the configurations for an experiment 34 // For details of individual configuration, see comments on the specific type 35 type configuration struct { 36 chainMgrConf *chainmgmt.ChainMgrConf 37 batchConf *chainmgmt.BatchConf 38 dataConf *dataConf 39 txConf *txConf 40 } 41 42 // defaultConf returns a configuration loaded with default values 43 func defaultConf() *configuration { 44 conf := &configuration{} 45 conf.chainMgrConf = &chainmgmt.ChainMgrConf{DataDir: "/tmp/fabric/ledgerPerfTests", NumChains: 1} 46 conf.batchConf = &chainmgmt.BatchConf{BatchSize: 10, SignBlock: false} 47 conf.txConf = &txConf{numTotalTxs: 100000, numParallelTxsPerChain: 100, numKeysInEachTx: 4} 48 conf.dataConf = &dataConf{numKVs: 100000, kvSize: 200} 49 return conf 50 } 51 52 // emptyConf returns a an empty configuration (with nested structure only) 53 func emptyConf() *configuration { 54 conf := &configuration{} 55 conf.chainMgrConf = &chainmgmt.ChainMgrConf{} 56 conf.batchConf = &chainmgmt.BatchConf{} 57 conf.txConf = &txConf{} 58 conf.dataConf = &dataConf{} 59 return conf 60 } 61 62 // confFromTestParams consumes the parameters passed by an experiment 63 // and returns the configuration loaded with the parsed param values 64 func confFromTestParams(testParams []string) *configuration { 65 conf := emptyConf() 66 flags := flag.NewFlagSet("testParams", flag.ExitOnError) 67 68 // chainMgrConf 69 dataDir := flags.String("DataDir", conf.chainMgrConf.DataDir, "Dir for ledger data") 70 numChains := flags.Int("NumChains", conf.chainMgrConf.NumChains, "Number of chains") 71 72 // txConf 73 numParallelTxsPerChain := flags.Int("NumParallelTxPerChain", 74 conf.txConf.numParallelTxsPerChain, "Number of TxSimulators concurrently on each chain") 75 76 numTotalTxs := flags.Int("NumTotalTx", 77 conf.txConf.numTotalTxs, "Number of total transactions") 78 79 numKeysInEachTx := flags.Int("NumKeysInEachTx", 80 conf.txConf.numKeysInEachTx, "number of keys operated upon in each Tx") 81 82 // batchConf 83 batchSize := flags.Int("BatchSize", 84 conf.batchConf.BatchSize, "number of Txs in each batch") 85 86 // dataConf 87 numKVs := flags.Int("NumKVs", 88 conf.dataConf.numKVs, "the keys are named as key_0, key_1,... upto key_(NumKVs-1)") 89 90 kvSize := flags.Int("KVSize", 91 conf.dataConf.kvSize, "size of the key-value in bytes") 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.numKeysInEachTx = *numKeysInEachTx 100 conf.batchConf.BatchSize = *batchSize 101 conf.dataConf.numKVs = *numKVs 102 conf.dataConf.kvSize = *kvSize 103 return conf 104 }