github.com/annchain/OG@v0.0.9/tests/test_tps/testTps.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package main 15 16 import ( 17 "fmt" 18 "github.com/annchain/OG/arefactor/og_interface" 19 "github.com/annchain/OG/common/math" 20 "github.com/annchain/OG/og/types" 21 "github.com/annchain/OG/rpc" 22 "time" 23 ) 24 25 func generateTxrequests(N int) []rpc.NewTxRequest { 26 var requests []rpc.NewTxRequest 27 oldpub, _ := og_interface.Signer.RandomKeyPair() 28 to := oldpub.Address().Hex() 29 toAdd := oldpub.Address() 30 pub, priv := og_interface.Signer.RandomKeyPair() 31 for i := 1; i < N; i++ { 32 from := pub.Address() 33 tx := types.Tx{ 34 TxBase: types.TxBase{ 35 Type: types.TxBaseTypeTx, 36 AccountNonce: uint64(i), 37 PublicKey: pub.KeyBytes[:], 38 }, 39 From: &from, 40 To: toAdd, 41 Value: math.NewBigInt(0), 42 } 43 tx.Signature = og_interface.Signer.Sign(priv, tx.SignatureTargets()).SignatureBytes[:] 44 //v:= og.TxFormatVerifier{} 45 //ok:= v.VerifySignature(&tx) 46 //target := tx.SignatureTargets() 47 //fmt.Println(hexutil.Encode(target)) 48 //if !ok { 49 // panic("not ok") 50 //} 51 request := rpc.NewTxRequest{ 52 Nonce: "1", 53 From: tx.From.Hex(), 54 To: to, 55 Value: tx.Value.String(), 56 Signature: tx.Signature.String(), 57 Pubkey: pub.String(), 58 } 59 requests = append(requests, request) 60 } 61 return requests 62 } 63 64 func testTPs() { 65 var N = 100000 66 var M = 99 67 debug = false 68 fmt.Println("started ", time.Now()) 69 70 var apps []app 71 for i := 0; i < M; i++ { 72 apps = append(apps, newApp()) 73 } 74 requests := generateTxrequests(N) 75 fmt.Println("gen txs ", time.Now(), len(requests)) 76 for i := 0; i < M; i++ { 77 go apps[i].ConsumeQueue() 78 } 79 for i := range requests { 80 j := i % M 81 apps[j].requestChan <- &requests[i] 82 } 83 time.Sleep(time.Second * 100) 84 for i := 0; i < M; i++ { 85 close(apps[i].quit) 86 } 87 return 88 }