-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathconfig.go
More file actions
102 lines (91 loc) · 2.83 KB
/
config.go
File metadata and controls
102 lines (91 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//go:build evm
package benchmark
import (
"os"
"strconv"
"testing"
"time"
)
// benchConfig holds all tunable parameters for a benchmark run.
// fields are populated from BENCH_* env vars with sensible defaults.
type benchConfig struct {
ServiceName string
// infrastructure (used by setupLocalEnv)
BlockTime string
SlotDuration string
GasLimit string
ScrapeInterval string
// load generation (used by test functions)
NumSpammers int
CountPerSpammer int
Throughput int
WarmupTxs int
GasUnitsToBurn int
MaxWallets int
MaxPending int
Rebroadcast int
BaseFee int
TipFee int
WaitTimeout time.Duration
}
func newBenchConfig(serviceName string) benchConfig {
return benchConfig{
ServiceName: serviceName,
BlockTime: envOrDefault("BENCH_BLOCK_TIME", "100ms"),
SlotDuration: envOrDefault("BENCH_SLOT_DURATION", "250ms"),
GasLimit: envOrDefault("BENCH_GAS_LIMIT", ""),
ScrapeInterval: envOrDefault("BENCH_SCRAPE_INTERVAL", "1s"),
NumSpammers: envInt("BENCH_NUM_SPAMMERS", 4),
CountPerSpammer: envInt("BENCH_COUNT_PER_SPAMMER", 5000),
Throughput: envInt("BENCH_THROUGHPUT", 200),
WarmupTxs: envInt("BENCH_WARMUP_TXS", 200),
GasUnitsToBurn: envInt("BENCH_GAS_UNITS_TO_BURN", 1_000_000),
MaxWallets: envInt("BENCH_MAX_WALLETS", 500),
MaxPending: envInt("BENCH_MAX_PENDING", 50_000),
Rebroadcast: envInt("BENCH_REBROADCAST", 0),
BaseFee: envInt("BENCH_BASE_FEE", 20),
TipFee: envInt("BENCH_TIP_FEE", 2),
WaitTimeout: envDuration("BENCH_WAIT_TIMEOUT", 10*time.Minute),
}
}
func (c benchConfig) totalCount() int {
return c.NumSpammers * c.CountPerSpammer
}
func (c benchConfig) log(t testing.TB) {
t.Logf("load: spammers=%d, count_per=%d, throughput=%d, warmup=%d, gas_units=%d, max_wallets=%d",
c.NumSpammers, c.CountPerSpammer, c.Throughput, c.WarmupTxs, c.GasUnitsToBurn, c.MaxWallets)
t.Logf("infra: block_time=%s, slot_duration=%s, gas_limit=%s, scrape_interval=%s",
c.BlockTime, c.SlotDuration, c.GasLimit, c.ScrapeInterval)
}
func envOrDefault(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}
// envInt returns the integer value of the given env var, or fallback if unset
// or unparseable. Invalid values silently fall back to the default.
func envInt(key string, fallback int) int {
v := os.Getenv(key)
if v == "" {
return fallback
}
n, err := strconv.Atoi(v)
if err != nil {
return fallback
}
return n
}
// envDuration returns the duration value of the given env var (e.g. "5m", "30s"),
// or fallback if unset or unparseable.
func envDuration(key string, fallback time.Duration) time.Duration {
v := os.Getenv(key)
if v == "" {
return fallback
}
d, err := time.ParseDuration(v)
if err != nil {
return fallback
}
return d
}