URL: dUrl,
}
+ client := &http.Client{}
+ for i := 0; i < iter; i++ {
+ rate := measureRequest(client, down, measurementBytes)
+ fmt.Printf("Down: MiB/s %v\n", rate/MiB)
+ }
+ for i := 0; i < iter; i++ {
+ rate := measureRequest(client, getUp(uUrl, measurementBytes), measurementBytes)
+ fmt.Printf("Up: MiB/s %v\n", rate/MiB)
+ }
+}
+
+// Can't figure out how to reset r on each request so unfortunately just reinstantiate :/
+func getUp(url *url.URL, measurementBytes int64) *http.Request {
var headers http.Header = make(map[string][]string)
headers.Add("Content-Type", "text/plain;charset=UTF-8")
r := io.NopCloser(bytes.NewReader(make([]byte, measurementBytes)))
- up := &http.Request{
+ return &http.Request{
Method: "POST",
- URL: uUrl,
+ URL: url,
Header: headers,
ContentLength: measurementBytes,
Body: r,
}
-
- client := &http.Client{}
- for i := 0; i < iter; i++ {
- rate := measureRequest(client, down, measurementBytes)
- fmt.Printf("Down: KiB/s %v\n", rate/KiB)
- }
- for i := 0; i < iter; i++ {
- rate := measureRequest(client, up, measurementBytes)
- fmt.Printf("Up: KiB/s %v\n", rate/KiB)
- }
}
// Returns the rate in bytes / s
log.Fatal(err)
}
defer resp.Body.Close()
+ // bufio seems less consistent than io.Discard but sometimes ends up faster
+ // basically, higher highs but lower lows, shouldn't matter for 90%ile measurements later
_, _ = io.ReadAll(bufio.NewReaderSize(resp.Body, int(b)))
return bytePerSecond(b, time.Since(start))
}