From bdfafffc8b7ec786ff41ea245f24920930eec720 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 22 May 2023 12:03:11 +0200 Subject: [PATCH] feat: emit connection establishment latency, upload and download times (#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 --- client.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index c1e5ee0..843f010 100644 --- a/client.go +++ b/client.go @@ -3,6 +3,7 @@ package perf import ( "crypto/tls" "encoding/binary" + "encoding/json" "fmt" "io" "log" @@ -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{ @@ -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 @@ -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 }