mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
fix: speedTest between peers keep the connection alive (#13120)
for longer durations keep the speedTest alive instead of timing them out based on ResponseHeaderTimeout.
This commit is contained in:
parent
556552340a
commit
0f7a51f461
@ -1014,9 +1014,18 @@ func (client *peerRESTClient) Speedtest(ctx context.Context, size, concurrent in
|
|||||||
return SpeedtestResult{}, err
|
return SpeedtestResult{}, err
|
||||||
}
|
}
|
||||||
defer http.DrainBody(respBody)
|
defer http.DrainBody(respBody)
|
||||||
|
waitReader, err := waitForHTTPResponse(respBody)
|
||||||
|
if err != nil {
|
||||||
|
return SpeedtestResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
dec := gob.NewDecoder(respBody)
|
|
||||||
var result SpeedtestResult
|
var result SpeedtestResult
|
||||||
err = dec.Decode(&result)
|
err = gob.NewDecoder(waitReader).Decode(&result)
|
||||||
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
|
}
|
||||||
|
if result.Error != "" {
|
||||||
|
return result, errors.New(result.Error)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
@ -1158,6 +1158,7 @@ func (s *peerRESTServer) GetPeerMetrics(w http.ResponseWriter, r *http.Request)
|
|||||||
type SpeedtestResult struct {
|
type SpeedtestResult struct {
|
||||||
Uploads uint64
|
Uploads uint64
|
||||||
Downloads uint64
|
Downloads uint64
|
||||||
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpeedtestObject implements "random-read" object reader
|
// SpeedtestObject implements "random-read" object reader
|
||||||
@ -1280,7 +1281,7 @@ func selfSpeedtest(ctx context.Context, size, concurrent int, duration time.Dura
|
|||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return SpeedtestResult{objUploadCount, objDownloadCount}, nil
|
return SpeedtestResult{Uploads: objUploadCount, Downloads: objDownloadCount}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *peerRESTServer) SpeedtestHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *peerRESTServer) SpeedtestHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -1313,17 +1314,15 @@ func (s *peerRESTServer) SpeedtestHandler(w http.ResponseWriter, r *http.Request
|
|||||||
duration = time.Second * 10
|
duration = time.Second * 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done := keepHTTPResponseAlive(w)
|
||||||
|
|
||||||
result, err := selfSpeedtest(r.Context(), size, concurrent, duration)
|
result, err := selfSpeedtest(r.Context(), size, concurrent, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.writeErrorResponse(w, err)
|
result.Error = err.Error()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enc := gob.NewEncoder(w)
|
done(nil)
|
||||||
if err := enc.Encode(result); err != nil {
|
logger.LogIf(r.Context(), gob.NewEncoder(w).Encode(result))
|
||||||
s.writeErrorResponse(w, errors.New("Encoding report failed: "+err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user