Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carry out an extra http request for warmup without considering for th… #189

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
if callback != nil {
callback(endTime)
}
}
time.Sleep(echoFreq)
}
Expand Down