Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 20, 2024
1 parent 93176da commit 0100ffd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
16 changes: 7 additions & 9 deletions testground/benchmark/benchmark/sendtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ def async_write_tx(account, tx, file_path):
file.write(ujson.dumps([raw_tx.hex()]))


def get_txs_foler(outdir: Path, group, global_seq):
folder = outdir / TMP_TXS_FOLDER / group / str(global_seq)
def get_txs_foler(outdir: Path, global_seq):
folder = outdir / TMP_TXS_FOLDER / str(global_seq)
folder.mkdir(parents=True, exist_ok=True)
return folder


def prepare_txs(
outdir: Path, group, global_seq, num_accounts, num_txs, max_workers=8000
):
folder = get_txs_foler(outdir, group, global_seq)
def prepare_txs(outdir: Path, global_seq, num_accounts, num_txs, max_workers=8000):
folder = get_txs_foler(outdir, global_seq)
accounts = [gen_account(global_seq, i + 1) for i in range(num_accounts)]
with ThreadPoolExecutor(max_workers=max_workers) as executor:
futs = []
Expand All @@ -60,12 +58,12 @@ def prepare_txs(
fut.result()
except Exception as e:
print("sign_transaction failed", e)
print(f"prepared {len(futs)} txs for {group} {global_seq}")
print(f"prepared {len(futs)} txs for {global_seq}")


def read_txs(outdir: Path, group, global_seq):
def read_txs(outdir: Path, global_seq):
txs = []
folder = get_txs_foler(outdir, group, global_seq)
folder = get_txs_foler(outdir, global_seq)
for file in folder.glob("*.json"):
with open(file, "r") as f:
tx_data = ujson.load(f)
Expand Down
14 changes: 5 additions & 9 deletions testground/benchmark/benchmark/stateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,10 @@ def _gen_txs(
for i in range(validators):
global_seq = i
if validator_generate_load:
prepare_txs(
outdir, VALIDATOR_GROUP, global_seq, num_accounts, num_txs, max_workers
)
prepare_txs(outdir, global_seq, num_accounts, num_txs, max_workers)
for i in range(fullnodes):
global_seq = i + validators
prepare_txs(
outdir, FULLNODE_GROUP, global_seq, num_accounts, num_txs, max_workers
)
prepare_txs(outdir, global_seq, num_accounts, num_txs, max_workers)


@cli.command()
Expand Down Expand Up @@ -253,8 +249,8 @@ def do_run(
txs = []
if group == FULLNODE_GROUP or cfg.get("validator-generate-load", True):
print("preparing", cfg["num_accounts"] * cfg["num_txs"], "txs")
prepare_txs(outdir, group, global_seq, cfg["num_accounts"], cfg["num_txs"])
txs = read_txs(outdir, group, global_seq)
prepare_txs(outdir, global_seq, cfg["num_accounts"], cfg["num_txs"])
txs = read_txs(outdir, global_seq)
else:
txs = []
print(f"loaded {len(txs)} txs")
Expand Down Expand Up @@ -374,7 +370,7 @@ def init_node_local(
num_accounts=num_accounts,
)
if group == FULLNODE_GROUP or validator_generate_load:
prepare_txs(outdir, group, global_seq, num_accounts, num_txs)
prepare_txs(outdir, global_seq, num_accounts, num_txs)
return packet


Expand Down

0 comments on commit 0100ffd

Please sign in to comment.