Skip to content

Commit 93de7b0

Browse files
committed
Adjust & improve
1 parent 4bed1d6 commit 93de7b0

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BASE_NODE_ENDPOINT_2=https://your-node-endpoint-2.com
99

1010
# Simple label for resulting filename
1111
REGION=singapore
12+
1213
NUMBER_OF_TRANSACTIONS=10
1314

1415
# Use eth_sendRawTransactionSync (true) or standard async method (false)

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ PRIVATE_KEY=your_private_key_here
2323
TO_ADDRESS=0xc2F695613de0885dA3bdd18E8c317B9fAf7d4eba
2424

2525
# If you are going with the asynchronous method and poll for the transaction receipts separately
26-
POLLING_INTERVAL_MS=100
26+
POLLING_INTERVAL_MS=50
2727

2828
BASE_NODE_ENDPOINT_1=https://your-node-endpoint-1.com
2929
BASE_NODE_ENDPOINT_2=https://your-node-endpoint-2.com
3030

3131
# This a simple label for the resulting filename to remember where you sent the test transactions from. Not used in any node routing.
3232
REGION=singapore
33+
3334
NUMBER_OF_TRANSACTIONS=10
3435

35-
# With `true`, the synchronous eth_sendRawTransactionSync method is used. With `false`, the asynchronous method is used with POLLING_INTERVAL_MS=100
36+
# With `true`, the synchronous eth_sendRawTransactionSync method is used. With `false`, the asynchronous method is used with POLLING_INTERVAL_MS=50
3637
SEND_TXN_SYNC=true
3738

3839
RUN_ENDPOINT2_TESTING=true
@@ -57,7 +58,7 @@ RUN_ENDPOINT2_TESTING=true
5758
**`POLLING_INTERVAL_MS`**:
5859
- Used only when `SEND_TXN_SYNC=false`
5960
- Defines how frequently (in milliseconds) to check for transaction receipts
60-
- Default: 100ms
61+
- Default: 50ms (recommended for accurate latency measurements)
6162
- Lower values = more frequent polling = faster detection but higher load
6263
- Not used when `SEND_TXN_SYNC=true` since confirmations are immediate
6364

@@ -81,6 +82,19 @@ docker build -t transaction-latency .
8182
docker run -v $(pwd)/data:/data --env-file .env --rm -it transaction-latency
8283
```
8384

85+
### Note about .env file loading
86+
87+
When running with Docker, you may see the log message:
88+
```
89+
Error loading .env file
90+
```
91+
92+
This is expected and harmless. The application uses two methods to load environment variables:
93+
1. **Docker's `--env-file` flag** (recommended): Sets environment variables at container runtime
94+
2. **Direct .env file loading**: Attempts to read the `.env` file from inside the container
95+
96+
Since we use the `--env-file` approach for security (keeping secrets out of the image), the direct file loading fails but the environment variables are still available via Docker. The application continues normally and all configuration works as expected.
97+
8498
## Results
8599

86100
After completion, results are saved to the `./data/` directory:

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func main() {
6666
sendTxnSync := os.Getenv("SEND_TXN_SYNC") == "true"
6767
runEndpoint2Testing := os.Getenv("RUN_ENDPOINT2_TESTING") != "false"
6868

69-
pollingIntervalMs := 100
69+
pollingIntervalMs := 50
7070
if pollingEnv := os.Getenv("POLLING_INTERVAL_MS"); pollingEnv != "" {
7171
if parsed, err := strconv.Atoi(pollingEnv); err == nil {
7272
pollingIntervalMs = parsed
@@ -137,10 +137,10 @@ func main() {
137137
time.Sleep(5 * time.Second)
138138

139139
if runEndpoint2Testing {
140-
log.Printf("Starting endpoint2 transactions")
140+
log.Printf("Starting endpoint2 transactions, syncMode=%v", sendTxnSync)
141141
for i := 0; i < numberOfTransactions; i++ {
142-
// Use async mode for endpoint2 testing
143-
timing, err := timeTransaction(chainId, privateKey, fromAddress, toAddress, endpoint2Client, false, pollingIntervalMs)
142+
// Use the same mode as endpoint1 for fair comparison
143+
timing, err := timeTransaction(chainId, privateKey, fromAddress, toAddress, endpoint2Client, sendTxnSync, pollingIntervalMs)
144144
if err != nil {
145145
endpoint2Errors += 1
146146
log.Printf("Failed to send transaction: %v", err)
@@ -155,12 +155,12 @@ func main() {
155155
log.Printf("Skipping endpoint2 transactions (RUN_ENDPOINT2_TESTING=false)")
156156
}
157157

158-
if err := writeToFile(fmt.Sprintf("./data/endpoint1-%s.csv", region), endpoint1Timings); err != nil {
158+
if err := writeToFile(fmt.Sprintf("/data/endpoint1-%s.csv", region), endpoint1Timings); err != nil {
159159
log.Fatalf("Failed to write to file: %v", err)
160160
}
161161

162162
if runEndpoint2Testing {
163-
if err := writeToFile(fmt.Sprintf("./data/endpoint2-%s.csv", region), endpoint2Timings); err != nil {
163+
if err := writeToFile(fmt.Sprintf("/data/endpoint2-%s.csv", region), endpoint2Timings); err != nil {
164164
log.Fatalf("Failed to write to file: %v", err)
165165
}
166166
}

0 commit comments

Comments
 (0)