@@ -12,6 +12,7 @@ import (
1212 "time"
1313
1414 "github.com/spf13/cobra"
15+ "golang.org/x/time/rate"
1516
1617 "github.com/sei-protocol/sei-load/config"
1718 "github.com/sei-protocol/sei-load/generator"
2526 configFile string
2627)
2728
28- // ResolvedSettings holds the final resolved settings after applying precedence
29- type ResolvedSettings struct {
30- Workers int
31- TPS float64
32- StatsInterval time.Duration
33- BufferSize int
34- DryRun bool
35- Debug bool
36- TrackReceipts bool
37- TrackBlocks bool
38- TrackUserLatency bool
39- Prewarm bool
40- }
41-
4229var rootCmd = & cobra.Command {
4330 Use : "seiload" ,
4431 Short : "Sei Chain Load Test v2" ,
@@ -149,8 +136,20 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
149136 return fmt .Errorf ("failed to create generator: %w" , err )
150137 }
151138
139+ // Create shared rate limiter for all workers if TPS is specified
140+ var sharedLimiter * rate.Limiter
141+ if settings .TPS > 0 {
142+ // Convert TPS to interval: 1/tps seconds = (1/tps) * 1e9 nanoseconds
143+ intervalNs := int64 ((1.0 / settings .TPS ) * 1e9 )
144+ sharedLimiter = rate .NewLimiter (rate .Every (time .Duration (intervalNs )), 1 )
145+ log .Printf ("📈 Rate limiting enabled: %.2f TPS shared across all workers" , settings .TPS )
146+ } else {
147+ // No rate limiting
148+ sharedLimiter = rate .NewLimiter (rate .Inf , 1 )
149+ }
150+
152151 // Create the sender from the config struct
153- snd , err := sender .NewShardedSender (cfg , settings .BufferSize , settings .Workers )
152+ snd , err := sender .NewShardedSender (cfg , settings .BufferSize , settings .Workers , sharedLimiter )
154153 if err != nil {
155154 return fmt .Errorf ("failed to create sender: %w" , err )
156155 }
@@ -192,11 +191,6 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
192191
193192 // Create dispatcher
194193 dispatcher := sender .NewDispatcher (gen , snd )
195- if settings .TPS > 0 {
196- // Convert TPS to interval: 1/tps seconds = (1/tps) * 1e9 nanoseconds
197- intervalNs := int64 ((1.0 / settings .TPS ) * 1e9 )
198- dispatcher .SetRateLimit (time .Duration (intervalNs ))
199- }
200194
201195 // Set statistics collector for dispatcher
202196 dispatcher .SetStatsCollector (collector )
0 commit comments