Skip to content

Commit

Permalink
feat: emit connection establishment latency, upload and download times (
Browse files Browse the repository at this point in the history
quic-go#8)

* feat: emit connectionEstablishedSeconds, uploadSeconds and downloadSeconds

- Makes emited values self-describing.
- Ensures accounting of connection establishment.
- Allows differentiation in subsequent data analysis.

* fix: remove superfluous space

* Move connectionEstablishmentTook above stream opening
  • Loading branch information
mxinden authored May 22, 2023
1 parent a03bc77 commit bdfafff
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package perf
import (
"crypto/tls"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"log"
Expand All @@ -11,7 +12,14 @@ import (
"github.com/quic-go/quic-go"
)

type Result struct {
ConnectionEstablishedSeconds float64 `json:"connectionEstablishedSeconds"`
UploadSeconds float64 `json:"uploadSeconds"`
DownloadSeconds float64 `json:"downloadSeconds"`
}

func RunClient(addr string, uploadBytes, downloadBytes uint64) error {
start := time.Now()
conn, err := quic.DialAddr(
addr,
&tls.Config{
Expand All @@ -23,6 +31,7 @@ func RunClient(addr string, uploadBytes, downloadBytes uint64) error {
if err != nil {
return err
}
connectionEstablishmentTook := time.Since(start)
str, err := conn.OpenStream()
if err != nil {
return err
Expand All @@ -33,7 +42,15 @@ func RunClient(addr string, uploadBytes, downloadBytes uint64) error {
}
log.Printf("uploaded %s: %.2fs (%s/s)", formatBytes(uploadBytes), uploadTook.Seconds(), formatBytes(bandwidth(uploadBytes, uploadTook)))
log.Printf("downloaded %s: %.2fs (%s/s)", formatBytes(downloadBytes), downloadTook.Seconds(), formatBytes(bandwidth(downloadBytes, downloadTook)))
fmt.Printf("{ \"latencies\": [ %f ]}\n", uploadTook.Seconds()+downloadTook.Seconds())
json, err := json.Marshal(Result{
ConnectionEstablishedSeconds: connectionEstablishmentTook.Seconds(),
UploadSeconds: uploadTook.Seconds(),
DownloadSeconds: downloadTook.Seconds(),
})
if err != nil {
return err
}
fmt.Println(string(json))
return nil
}

Expand Down

0 comments on commit bdfafff

Please sign in to comment.