diff --git a/orderer/common/performance/utils.go b/orderer/common/performance/utils.go index c5447008a7a..3f51ff254a4 100644 --- a/orderer/common/performance/utils.go +++ b/orderer/common/performance/utils.go @@ -15,8 +15,7 @@ import ( "github.com/hyperledger/fabric/common/localmsp" "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - mspmgmt "github.com/hyperledger/fabric/msp/mgmt" - "github.com/hyperledger/fabric/orderer/common/localconfig" + cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" protosutils "github.com/hyperledger/fabric/protos/utils" @@ -27,25 +26,9 @@ const ( Kilo = 1024 // TODO Consider adding a unit pkg ) -var conf *config.TopLevel - var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz") -var channelProfile *genesisconfig.Profile - -func init() { - rand.Seed(time.Now().UnixNano()) - - conf = config.Load() - - // Load local MSP - err := mspmgmt.LoadLocalMsp(conf.General.LocalMSPDir, conf.General.BCCSP, conf.General.LocalMSPID) - if err != nil { - panic(fmt.Errorf("Failed to initialize local MSP: %s", err)) - } - - channelProfile = genesisconfig.Load(genesisconfig.SampleSingleMSPChannelV11Profile) -} +var seedOnce sync.Once // MakeNormalTx creates a properly signed transaction that could be used against `broadcast` API func MakeNormalTx(channelID string, size int) *cb.Envelope { @@ -94,6 +77,8 @@ func OrdererExec(f func(s *BenchmarkServer)) { // RandomID generates a random string of num chars func RandomID(num int) string { + seedOnce.Do(func() { rand.Seed(time.Now().UnixNano()) }) + b := make([]rune, num) for i := range b { b[i] = letterRunes[rand.Intn(len(letterRunes))] @@ -102,7 +87,7 @@ func RandomID(num int) string { } // CreateChannel creates a channel with randomly generated ID of length 10 -func CreateChannel(server *BenchmarkServer) string { +func CreateChannel(server *BenchmarkServer, channelProfile *genesisconfig.Profile) string { client := server.CreateBroadcastClient() defer client.Close() diff --git a/orderer/common/server/benchmark_test.go b/orderer/common/server/benchmark_test.go index 132c1558cf2..c5978bd15f3 100644 --- a/orderer/common/server/benchmark_test.go +++ b/orderer/common/server/benchmark_test.go @@ -110,6 +110,7 @@ const ( // be less than 13 KB. AbsoluteMaxBytes = 15 // KB PreferredMaxBytes = 10 // KB + ChannelProfile = localconfig.SampleSingleMSPChannelV11Profile ) var envvars = map[string]string{ @@ -356,6 +357,15 @@ func benchmarkOrderer( numOfOrderer int, multiplex bool, ) { + // Initialization shared by all orderers + conf := config.Load() + initializeLoggingLevel(conf) + initializeLocalMsp(conf) + perf.InitializeServerPool(numOfOrderer) + + // Load sample channel profile + channelProfile := localconfig.Load(ChannelProfile) + // Calculate intermediate variables used internally. See the comment at the beginning // of this file for the purpose of these vars. txPerClient := totalTx / (broadcastClientPerChannel * numOfChannels * numOfOrderer) @@ -376,12 +386,6 @@ func benchmarkOrderer( var txCount uint64 // Atomic counter to keep track of actual tx sent - // Initialization shared by all orderers - conf := config.Load() - initializeLoggingLevel(conf) - initializeLocalMsp(conf) - perf.InitializeServerPool(numOfOrderer) - // Generate a random system channel id for each test run, // so it does not recover ledgers from previous run. systemchannel := "system-channel-" + perf.RandomID(5) @@ -419,7 +423,7 @@ func benchmarkOrderer( channelIDs := make([]string, numOfChannels) txs := make(map[string]*cb.Envelope) for i := 0; i < numOfChannels; i++ { - id := perf.CreateChannel(benchmarkServers[0]) // We only need to create channel on one orderer + id := perf.CreateChannel(benchmarkServers[0], channelProfile) // We only need to create channel on one orderer channelIDs[i] = id txs[id] = perf.MakeNormalTx(id, msgSize) } diff --git a/sampleconfig/configtx.yaml b/sampleconfig/configtx.yaml index 779e7308b13..b13189b88fe 100644 --- a/sampleconfig/configtx.yaml +++ b/sampleconfig/configtx.yaml @@ -59,7 +59,7 @@ Profiles: - <<: *SampleOrg AdminPrincipal: Role.MEMBER - # SampleDevModeSoloV1.1 mimics the SampleDevModeKafka definition + # SampleDevModeSoloV1.1 mimics the SampleDevModeSolo definition # but additionally defines the v1.1 only capabilities which do # not allow a mixed v1.0.x v1.1.x network SampleDevModeSoloV1_1: