Skip to content

Commit

Permalink
fix(http-ping): Carry out an extra http request for warmup without co…
Browse files Browse the repository at this point in the history
…nsidering for the latency calculation (#189)
  • Loading branch information
danielealbano committed Apr 28, 2024
1 parent f5ed869 commit c380a22
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions speedtest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ func (s *Server) HTTPPing(
if err != nil {
return nil, err
}
// carry out an extra request to warm up the connection and ensure the first request is not going to affect the
// overall estimation
echoTimes++
for i := 0; i < echoTimes; i++ {
sTime := time.Now()
resp, err := s.Context.doer.Do(req)
Expand All @@ -296,10 +299,13 @@ func (s *Server) HTTPPing(
}
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
latencies = append(latencies, endTime.Nanoseconds()/2)
dbg.Printf("2RTT: %s\n", endTime)
if callback != nil {
callback(endTime / 2)
if i > 0 {
latency := endTime.Nanoseconds()
latencies = append(latencies, latency)
dbg.Printf("2RTT: %s\n", latency)

Check failure on line 305 in speedtest/request.go

View workflow job for this annotation

GitHub Actions / lint

printf: (*github.com/showwin/speedtest-go/speedtest.Debug).Printf format %s has arg latency of wrong type int64 (govet)
if callback != nil {
callback(endTime)
}
}
time.Sleep(echoFreq)
}
Expand Down

0 comments on commit c380a22

Please sign in to comment.