Skip to content

Commit

Permalink
run load generator and jsonnet config
Browse files Browse the repository at this point in the history
quit

wait for grpc service
  • Loading branch information
yihuang committed Jul 4, 2024
1 parent d0165af commit 59e953f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 83 deletions.
21 changes: 3 additions & 18 deletions testground/benchmark/benchmark/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
import subprocess
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path

import web3

from .cli import ChainCommand
from .context import Context
from .peer import CONTAINER_CRONOSD_PATH, bootstrap
from .sendtx import fund_test_accounts, sendtx
from .utils import export_eth_account, wait_for_block, wait_for_port
from .sendtx import generate_load
from .utils import wait_for_block, wait_for_port


def influxdb_url():
Expand Down Expand Up @@ -37,21 +36,7 @@ def entrypoint(ctx: Context):

test_finish_entry = f"finish-test-{ctx.params.test_group_id}"
if not ctx.is_validator:
w3 = web3.Web3(web3.providers.HTTPProvider("http://localhost:8545"))
assert w3.eth.chain_id == 777
genesis_account = export_eth_account(cli, "account")
accounts = fund_test_accounts(w3, genesis_account, ctx.params.num_accounts)
with ThreadPoolExecutor(max_workers=ctx.params.num_accounts) as executor:
futs = (
executor.submit(sendtx, w3, acct, ctx.params.num_txs)
for acct in accounts
)
for fut in as_completed(futs):
try:
fut.result()
except Exception as e:
print("test task failed", e)

generate_load(cli, ctx.params.num_accounts, ctx.params.num_txs)
print("finish test", ctx.group_seq)
ctx.sync.signal_and_wait(
test_finish_entry, ctx.params.test_group_instance_count
Expand Down
17 changes: 16 additions & 1 deletion testground/benchmark/benchmark/sendtx.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import time
from concurrent.futures import ThreadPoolExecutor, as_completed

import web3
from eth_account import Account

from .utils import send_transaction
from .utils import export_eth_account, send_transaction

TEST_AMOUNT = 1000000000000000000
GAS_PRICE = 1000000000
Expand Down Expand Up @@ -54,3 +55,17 @@ def sendtx(w3: web3.Web3, acct: Account, tx_amount: int):

if nonce % 100 == 0:
print(f"{acct.address} sent {nonce} transactions")


def generate_load(cli, num_accounts, num_txs, **kwargs):
w3 = web3.Web3(web3.providers.HTTPProvider("http://localhost:8545"))
assert w3.eth.chain_id == 777
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)
for fut in as_completed(futs):
try:
fut.result()
except Exception as e:
print("test task failed", e)
31 changes: 18 additions & 13 deletions testground/benchmark/benchmark/stateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
import os
import socket
import subprocess
import time

Check failure on line 5 in testground/benchmark/benchmark/stateless.py

View workflow job for this annotation

GitHub Actions / Lint python

./testground/benchmark/benchmark/stateless.py:5:1: F401 'time' imported but unused
from pathlib import Path
from typing import List

import fire

from .cli import ChainCommand
from .peer import (
CONTAINER_CRONOSD_PATH,
FULLNODE_GROUP,
VALIDATOR_GROUP,
gen_genesis,
init_node,
patch_configs,
)
from .peer import (CONTAINER_CRONOSD_PATH, FULLNODE_GROUP, VALIDATOR_GROUP,

Check failure on line 12 in testground/benchmark/benchmark/stateless.py

View workflow job for this annotation

GitHub Actions / Lint python

./testground/benchmark/benchmark/stateless.py:12:20: BLK100 Black would make changes.
gen_genesis, init_node, patch_configs)
from .sendtx import generate_load
from .topology import connect_all
from .types import PeerPacket
from .utils import wait_for_block, wait_for_port
Expand Down Expand Up @@ -64,6 +60,8 @@ def run(
validators: int,
cronosd=CONTAINER_CRONOSD_PATH,
global_seq=None,
num_accounts=10,
num_txs=1000,
):
outdir = Path(outdir)
if global_seq is None:
Expand All @@ -84,13 +82,20 @@ def run(
cli = ChainCommand(cronosd)
wait_for_port(26657)
wait_for_port(8545)
wait_for_port(9090)
wait_for_block(cli, 1)

proc.kill()
try:
proc.wait(5)
except subprocess.TimeoutExpired:
pass
if group == VALIDATOR_GROUP:
# validators don't quit
proc.wait()
else:
generate_load(cli, num_accounts, num_txs, home=home)

proc.kill()
try:
proc.wait()
except subprocess.TimeoutExpired:
pass


def init_node_local(
Expand Down
5 changes: 3 additions & 2 deletions testground/benchmark/benchmark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def send_transaction(w3, tx, acct, wait=True):
return txhash


def export_eth_account(cli, name: str) -> Account:
def export_eth_account(cli, name: str, **kwargs) -> Account:
kwargs.setdefault("keyring_backend", "test")
return Account.from_key(

Check failure on line 98 in testground/benchmark/benchmark/utils.py

View workflow job for this annotation

GitHub Actions / Lint python

./testground/benchmark/benchmark/utils.py:98:29: BLK100 Black would make changes.
cli("keys", "unsafe-export-eth-key", name, keyring_backend="test")
cli("keys", "unsafe-export-eth-key", name, **kwargs)
)
17 changes: 17 additions & 0 deletions testground/benchmark/compositions/docker-compose.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
std.manifestYamlDoc({
services: {
['testplan-' + i]: {
image: 'ghcr.io/crypto-org-chain/cronos-testground:latest',
command: 'stateless-testcase run /data 3 --num_accounts=10 --num_txs=1000',
container_name: 'testplan-' + i,
volumes: [
@'${DATADIR:-/tmp/data/out}:/data',
'/tmp:/tmp',
],
environment: {
JOB_COMPLETION_INDEX: i,
},
}
for i in std.range(0, 10)
},
})
41 changes: 0 additions & 41 deletions testground/benchmark/compositions/docker-compose.yml

This file was deleted.

8 changes: 0 additions & 8 deletions testground/benchmark/compositions/template.yml

This file was deleted.

0 comments on commit 59e953f

Please sign in to comment.