# Performance Test Design ## Configuration ```json= { "node": "ws://127.0.0.1:9988", "threads": 4, "senders-count": 100, "signer-seed": "//Alice", "block-time": 12, "amount": 1, "base-tps": 50 } ``` 1. Set base TPS, such as `baseTPS = 50`, and our block time is 12. So It means that we should send 50 * 12 = 600 transactions with 12 seconds. 2. Set `senders-count` as 100, which means there're 100 senders to sign 6(600 / 100) transactions on average. 3. Before get into the real performance test, prepare 6000 recerivers or more, it depends on how many transactions we want to send. ## Preparation 1. Randomly generate 100 senders, and `Alice` will send 10000 tokens to each sender. 2. Randomly generate 6000 receivers, definitely we can save these receivers, it really takes lots of time to generate. 3. After step 1 and 2 are done, sleep 12 seconds, avoid the transactions from step 1 interferes the real performance test. ## Test 1. According to the `baseTPS = 50`, calculate how many transaction we need to send in current round. ``` baseTPS = 50 blockTime = 12 needToBeSentExtrinsics = baseTPS * blockTime = 600 ``` So each signer will sign 6 transactions. Before start to sign transactions, we record current timepoint. ```javascript= const startTime = new Date().getMilliseconds(); ... ... ... const endTime = new Date().getMilliseconds(); ``` And once all `needToBeSentExtrinsics` are sent within 12 seconds, the script will sleep for a while. If not, continue step 2. ```javascript= let duration = endTime - startTime; if (endTime - startTime < blockTime * 1000) { await sleep_ms(blockTime * 1000 - duration); } ``` 2. Once step 1 is done, get latest block and check how many transactions(except built-in transactions) in it. So the real TPS is ```javascript= let currentTPS = getAllExtrinsicsFromLatestBlock(api) / blockTime; ``` Surely we should record the block time: ```javascript= const lastBlcokTime = await getBlockTime(api); allTimeBlockTime += lastBlcokTime; round += 1; console.log("average block time: ", allTimeBlockTime / round); ``` 3. If step 1 and step 2 are done, increase `baseTPS` by 5, continue the next round test. ```javascript= baseTPS += 5; ``` > Tips: > 1. Currently, all transactions are sent by utility.batch. > 2. Javascript doesn't support multithread, so it's hard to start multi clients. ## Questions 1. Should we consider when to send transactions? I mean once last block is produced, start next round of test. But sometimes, perhaps current block time reachs 3.5 seconds, so right now, it's not a good time to send transactions. 2. If we start to test it on `Baikel`, each client points to different full node or collator. This might help the performance.