Optimize latency checks for significantly faster performance
- Reduced ping interval from 1s to 200ms (5x faster per relay) - Reduced ping count from 5 to 3 (still reliable, but faster) - Increased latency workers from 30 to 100 (3.3x more parallelism) - Increased liveness workers from 20 to 50 (2.5x more parallelism) - Reduced timeouts: liveness from 3s to 1s, latency from 10s to 3s - Expected speedup: ~10x faster overall execution time
This commit is contained in:
parent
0fe71520c5
commit
df3c6c6a0e
@ -91,8 +91,8 @@ func CollectRelayLatencies(relays []Relay) []RelayLatency {
|
||||
livenessResults := make(chan RelayLatency, len(relays))
|
||||
bar := progressbar.Default(int64(len(relays)), "Checking liveness")
|
||||
|
||||
// Start 20 workers for liveness checks
|
||||
numLivenessWorkers := 20
|
||||
// Start 50 workers for liveness checks (increased from 20)
|
||||
numLivenessWorkers := 50
|
||||
for w := 0; w < numLivenessWorkers; w++ {
|
||||
wg.Add(1)
|
||||
go livenessWorker(w, livenessJobs, livenessResults, &wg, bar)
|
||||
@ -123,8 +123,8 @@ func CollectRelayLatencies(relays []Relay) []RelayLatency {
|
||||
latencyResults := make(chan RelayLatency, len(liveRelays))
|
||||
bar = progressbar.Default(int64(len(liveRelays)), "Measuring latency")
|
||||
|
||||
// Start 30 workers for latency checks
|
||||
numLatencyWorkers := 30
|
||||
// Start 100 workers for latency checks (increased from 30)
|
||||
numLatencyWorkers := 100
|
||||
for w := 0; w < numLatencyWorkers; w++ {
|
||||
wg.Add(1)
|
||||
go latencyWorker(w, latencyJobs, latencyResults, &wg, bar)
|
||||
|
@ -43,7 +43,7 @@ func (r Relay) CheckLiveness() (bool, time.Duration, error) {
|
||||
return false, 0, err
|
||||
}
|
||||
pinger.Count = 1
|
||||
pinger.Timeout = 3 * time.Second // Increased timeout for the single ping
|
||||
pinger.Timeout = 1 * time.Second // Reduced from 3 seconds for faster checks
|
||||
pinger.SetPrivileged(true)
|
||||
if err := pinger.Run(); err != nil {
|
||||
return false, 0, err
|
||||
@ -63,15 +63,15 @@ func (r Relay) CheckLiveness() (bool, time.Duration, error) {
|
||||
return true, stats.AvgRtt, nil
|
||||
}
|
||||
|
||||
// MeasureLatency measures the minimum latency of the relay over 5 pings
|
||||
// MeasureLatency measures the minimum latency of the relay over 3 pings
|
||||
func (r Relay) MeasureLatency() (time.Duration, error) {
|
||||
pinger, err := ping.NewPinger(r.Ipv4AddrIn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
pinger.Count = 5
|
||||
pinger.Interval = 1 * time.Second // Adding interval between pings
|
||||
pinger.Timeout = 10 * time.Second // Increased overall timeout
|
||||
pinger.Count = 3 // Reduced from 5 to 3 for faster measurements
|
||||
pinger.Interval = 200 * time.Millisecond // Reduced from 1 second to 200ms
|
||||
pinger.Timeout = 3 * time.Second // Adjusted timeout for 3 pings
|
||||
pinger.SetPrivileged(true)
|
||||
if err := pinger.Run(); err != nil {
|
||||
return 0, err
|
||||
|
Loading…
Reference in New Issue
Block a user