Skip to content

Commit 228f4ea

Browse files
authored
Merge pull request #96 from Federico2014/fix/stress_test
fix(stress_test): fix the stress test tool
2 parents 2d72111 + 530c020 commit 228f4ea

File tree

3 files changed

+33
-31
lines changed

3 files changed

+33
-31
lines changed

tools/stress_test/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,14 @@ broadcastTx = {
115115

116116
- `relayTx`: configure whether to broadcast the relayed transactions;
117117

118-
- `broadcastUrl`: configure the broadcast url list;
119-
120118
- `tpsLimit`: configure the maximum broadcast transactions per second;
121119

122120
- `saveTxId`: configure whether to save the transaction id of the broadcast transactions.
123121

124122
*Note*: we can use the [DBFork](../toolkit/DBFork.md) tool to get enough `TRX/TRC10/TRC20` balances of address corresponding
125123
to the `privateKey` for the stress test.
126124

127-
Then we can execute the following `generate` subcommand:
125+
Then we can execute the following `broadcast` subcommand:
128126

129127
```shell
130128
# execute full command

tools/stress_test/src/main/java/org/tron/trxs/BroadcastGenerate.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,20 @@ public void broadcastTransactions() throws IOException, InterruptedException {
9393
long endTps;
9494
float currentTps;
9595
while ((transaction = Transaction.parseDelimitedFrom(fis)) != null) {
96+
TransactionMessage message = new TransactionMessage(transaction);
97+
int peerCnt = tronNetService.fastBroadcastTransaction(message);
98+
while (peerCnt <= 0) {
99+
logger.warn("broadcast task {}/{} has no available peers to broadcast, please wait",
100+
index + 1, totalTask);
101+
Thread.sleep(100);
102+
peerCnt = tronNetService.fastBroadcastTransaction(message);
103+
}
104+
96105
trxCount++;
106+
if (trxCount % 10000 == 0) {
107+
logger.info("total broadcast tx num: {}", trxCount);
108+
}
109+
97110
if (cnt > TxConfig.getInstance().getBroadcastTpsLimit()) {
98111
endTps = System.currentTimeMillis();
99112
if (endTps - startTps <= 1000) {
@@ -107,19 +120,12 @@ public void broadcastTransactions() throws IOException, InterruptedException {
107120
cnt = 0;
108121
startTps = System.currentTimeMillis();
109122
} else {
110-
TransactionMessage message = new TransactionMessage(transaction);
111-
int peerCnt = tronNetService.fastBroadcastTransaction(message);
112-
while (peerCnt <= 0) {
113-
logger.warn("broadcast task {}/{} has no available peers to broadcast, please wait",
114-
index + 1, totalTask);
115-
Thread.sleep(100);
116-
peerCnt = tronNetService.fastBroadcastTransaction(message);
117-
}
118-
if (saveTrxId) {
119-
transactionIDs.add(transaction);
120-
}
121123
cnt++;
122124
}
125+
126+
if (saveTrxId) {
127+
transactionIDs.add(transaction);
128+
}
123129
}
124130

125131
isFinishSend = true;

tools/stress_test/src/main/java/org/tron/trxs/BroadcastRelay.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ public void broadcastTransactions() {
8383
long startTps = System.currentTimeMillis();
8484
long endTps;
8585
while ((transaction = Transaction.parseDelimitedFrom(fis)) != null) {
86+
TransactionMessage message = new TransactionMessage(transaction);
87+
int peerCnt = tronNetService.fastBroadcastTransaction(message);
88+
while (peerCnt <= 0) {
89+
logger.warn("broadcast relay task has no available peers to broadcast, please wait");
90+
Thread.sleep(100);
91+
peerCnt = tronNetService.fastBroadcastTransaction(message);
92+
}
93+
8694
trxCount++;
95+
if (trxCount % 10000 == 0) {
96+
logger.info("total broadcast tx num: {}", trxCount);
97+
}
8798
if (cnt > TxConfig.getInstance().getBroadcastTpsLimit()) {
8899
endTps = System.currentTimeMillis();
89100
if (endTps - startTps < 1000) {
@@ -92,25 +103,12 @@ public void broadcastTransactions() {
92103
cnt = 0;
93104
startTps = System.currentTimeMillis();
94105
} else {
95-
try {
96-
TransactionMessage message = new TransactionMessage(transaction);
97-
int peerCnt = tronNetService.fastBroadcastTransaction(message);
98-
while (peerCnt <= 0) {
99-
logger.warn("broadcast relay task has no available peers to broadcast, please wait");
100-
Thread.sleep(100);
101-
peerCnt = tronNetService.fastBroadcastTransaction(message);
102-
}
103-
if (trxCount % 1000 == 0) {
104-
logger.info("total broadcast tx num: {}", trxCount);
105-
}
106-
} catch (Exception e) {
107-
e.printStackTrace();
108-
}
109-
if (saveTrxId) {
110-
transactionIDs.add(transaction);
111-
}
112106
cnt++;
113107
}
108+
109+
if (saveTrxId) {
110+
transactionIDs.add(transaction);
111+
}
114112
}
115113

116114
isFinishSend = true;

0 commit comments

Comments
 (0)