From ef9340464ecba996a3d05d2a1d8d9319621087d0 Mon Sep 17 00:00:00 2001 From: huangyi Date: Fri, 30 Aug 2024 12:09:56 +0800 Subject: [PATCH 1/3] Problem: concurrent send_tx shares web3 instance it might limit the concurrent performance --- testground/benchmark/benchmark/sendtx.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testground/benchmark/benchmark/sendtx.py b/testground/benchmark/benchmark/sendtx.py index 34bb9f2cd0..50ef4d8c31 100644 --- a/testground/benchmark/benchmark/sendtx.py +++ b/testground/benchmark/benchmark/sendtx.py @@ -32,6 +32,8 @@ def fund_test_accounts(w3, from_account, num_accounts) -> [Account]: def sendtx(w3: web3.Web3, acct: Account, tx_amount: int): + w3 = web3.Web3(web3.providers.HTTPProvider("http://localhost:8545")) + chain_id = w3.eth.chain_id initial_nonce = w3.eth.get_transaction_count(acct.address) print( "test begin, address:", @@ -50,6 +52,7 @@ def sendtx(w3: web3.Web3, acct: Account, tx_amount: int): "nonce": nonce, "gas": 21000, "gasPrice": GAS_PRICE, + "chainId": chain_id, } try: send_transaction(w3, tx, acct, wait=False) From 7c10fe9ca3d10b6901321e2aaccfdab2c95bb1c5 Mon Sep 17 00:00:00 2001 From: huangyi Date: Fri, 30 Aug 2024 12:11:49 +0800 Subject: [PATCH 2/3] cleanup --- testground/benchmark/benchmark/sendtx.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/testground/benchmark/benchmark/sendtx.py b/testground/benchmark/benchmark/sendtx.py index 50ef4d8c31..1d42d86f6e 100644 --- a/testground/benchmark/benchmark/sendtx.py +++ b/testground/benchmark/benchmark/sendtx.py @@ -31,7 +31,7 @@ def fund_test_accounts(w3, from_account, num_accounts) -> [Account]: return accounts -def sendtx(w3: web3.Web3, acct: Account, tx_amount: int): +def sendtx(acct: Account, tx_amount: int): w3 = web3.Web3(web3.providers.HTTPProvider("http://localhost:8545")) chain_id = w3.eth.chain_id initial_nonce = w3.eth.get_transaction_count(acct.address) @@ -54,19 +54,8 @@ def sendtx(w3: web3.Web3, acct: Account, tx_amount: int): "gasPrice": GAS_PRICE, "chainId": chain_id, } - try: - send_transaction(w3, tx, acct, wait=False) - except ValueError as e: - msg = str(e) - if "invalid nonce" in msg: - print("invalid nonce and retry", nonce) - time.sleep(1) - continue - if "tx already in mempool" not in msg: - raise - + send_transaction(w3, tx, acct, wait=False) nonce += 1 - if nonce % 100 == 0: print(f"{acct.address} sent {nonce} transactions") @@ -86,7 +75,7 @@ def generate_load(cli, num_accounts, num_txs, **kwargs): genesis_account = export_eth_account(cli, "account", **kwargs) accounts = fund_test_accounts(w3, genesis_account, num_accounts) with ThreadPoolExecutor(max_workers=num_accounts) as executor: - futs = (executor.submit(sendtx, w3, acct, num_txs) for acct in accounts) + futs = (executor.submit(sendtx, acct, num_txs) for acct in accounts) for fut in as_completed(futs): try: fut.result() From 20b1cb30b5c6ddb6d875d36ed1bc5419676b9416 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 30 Aug 2024 12:41:42 +0800 Subject: [PATCH 3/3] cleanup --- testground/benchmark/benchmark/sendtx.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testground/benchmark/benchmark/sendtx.py b/testground/benchmark/benchmark/sendtx.py index 1d42d86f6e..d8ba5d74c7 100644 --- a/testground/benchmark/benchmark/sendtx.py +++ b/testground/benchmark/benchmark/sendtx.py @@ -1,4 +1,3 @@ -import time from concurrent.futures import ThreadPoolExecutor, as_completed import web3