|
| 1 | +# Load Testing |
| 2 | + |
| 3 | +The `load` package is a framework for performing load testing |
| 4 | +against an instance of the C-Chain. It allows for simulation of various |
| 5 | +transaction scenarios to test network performance, transaction throughput, and system |
| 6 | +resilience under different workloads. |
| 7 | + |
| 8 | +This package also comes with `main`, a subpackage executable which runs a load test against |
| 9 | +an instance of the C-Chain. For information on how to run the executable, refer to |
| 10 | +the `main` [README.md](./main/README.md). |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +Using the `load` package has so far been coupled with `tmpnet`, a framework that |
| 15 | +enables orchestration of temporary AvalancheGo networks. For more details as to |
| 16 | +its capabilities and configuration, refer to the `tmpnet` [README.md](../fixture/tmpnet/README.md). |
| 17 | + |
| 18 | +## Components |
| 19 | + |
| 20 | +### Worker |
| 21 | + |
| 22 | +Workers represent accounts which will be used for load testing. Each worker consists of a private key, nonce, and a network client - these values are used to create a wallet for load testing. |
| 23 | + |
| 24 | +### Wallet |
| 25 | + |
| 26 | +A wallet manages account state and transaction lifecycle for a single account. |
| 27 | + |
| 28 | +The main function of wallets is to send transactions; wallets take signed transactions |
| 29 | +and send them to the network while monitoring block headers to detect transaction inclusion. A wallet |
| 30 | +considers a transaction successful if its execution succeeded, and returns an error otherwise. |
| 31 | +Upon confirming a transaction was successful, a wallet increments its nonce by one, ensuring its account |
| 32 | +state matches that of the network. |
| 33 | + |
| 34 | +Wallets are not thread-safe and each account should have at most one wallet |
| 35 | +instance associated with it. Having multiple wallets associated with a single |
| 36 | +account, or using an account outside of a wallet, can cause synchronization |
| 37 | +issues. This risks a wallet's state becoming inconsistent with the network, |
| 38 | +potentially leading to failed transactions. |
| 39 | + |
| 40 | +Wallets are not thread-safe and each account should have at most one wallet instance associated with it. |
| 41 | + |
| 42 | +### Generator |
| 43 | + |
| 44 | +The generator executes multiple tests concurrently against the network. The key features of the |
| 45 | +generator are as follows: |
| 46 | + |
| 47 | +- **Parallel Execution**: Runs a goroutine per wallet for concurrent test execution. |
| 48 | +- **Timeout Management**: Supports both overall load test timeout and a timeout per-test. |
| 49 | +- **Error Recovery**: Automatically recovers from test failures to ensure continuous load generation. |
| 50 | +- **Metrics**: Creates metrics during wallet initialization and tracks performance throughout execution. |
| 51 | + |
| 52 | +The generator starts a goroutine for each wallet to execute tests asynchronously, maximizing throughput while maintaining isolation between accounts. |
| 53 | + |
| 54 | +### Tests |
| 55 | + |
| 56 | +The `load` package performs load testing by continuously running a series of tests. This approach provides the following benefits: |
| 57 | + |
| 58 | +- **Correctness**: Each test validates transaction execution and state changes, ensuring the network behaves as expected under load |
| 59 | +- **Reproducibility**: Standardized test scenarios with consistent parameters enable repeatable performance measurements and regression detection |
| 60 | + |
| 61 | +Each test must satisfy the following interface for compatibility with the load generator: |
| 62 | + |
| 63 | +```go |
| 64 | +type Test interface { |
| 65 | + // Run should create a signed transaction and broadcast it to the network via wallet. |
| 66 | + Run(tc tests.TestContext, ctx context.Context, wallet *Wallet) |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +#### Available Test Types |
| 71 | + |
| 72 | +The `load` package provides a comprehensive suite of test types designed to stress different aspects of EVM execution. Each test targets specific performance characteristics and resource usage patterns. |
| 73 | + |
| 74 | +| Test Type | Description | |
| 75 | +| ----------------- | --------------------------------------------------------------- | |
| 76 | +| Transfer | Performs self-transfer of 0 AVAX | |
| 77 | +| Read | Performs multiple storage reads from contract state | |
| 78 | +| Write | Executes equential storage writes to new contract storage slots | |
| 79 | +| StateModification | Updates existing storage values or creates new ones | |
| 80 | +| Hashing | Executes Keccak256 hash operations in a loop | |
| 81 | +| PureCompute | Performs CPU-intensive mathematical computations | |
| 82 | +| Memory | Allocates and manipulates dynamic arrays | |
| 83 | +| CallDepth | Performs recursive function calls to test stack limits | |
| 84 | +| ContractCreation | Deploys new contracts during execution | |
| 85 | +| ExternalCall | Makes calls to external contract functions | |
| 86 | +| LargeEvent | Emits events with large data payloads | |
| 87 | +| TrieStress | Performs insert operations on TrieDB | |
| 88 | + |
| 89 | +Additionally, there is a `RandomTest` which executes one of the aforementioned tests, selected uniformly at random. |
| 90 | +This test is particular useful for mimicking the diverse transactions patterns seen on blockchains like the C-Chain. |
| 91 | + |
| 92 | +### Metrics |
| 93 | + |
| 94 | +The package exposes Prometheus metrics for comprehensive load test monitoring: |
| 95 | + |
| 96 | +- **`txs_issued`** (Counter): Total number of transactions submitted to the network |
| 97 | +- **`tx_issuance_latency`** (Histogram): Time from transaction creation to network submission |
| 98 | +- **`tx_confirmation_latency`** (Histogram): Time from network submission to block confirmation |
| 99 | +- **`tx_total_latency`** (Histogram): End-to-end time from creation to confirmation |
| 100 | + |
| 101 | +These metrics are registered with the registry passed into the load generator during initialization and are updated via the wallets during test execution. |
| 102 | + |
0 commit comments