Skip to content

Commit

Permalink
expose a single latency measurement (#12)
Browse files Browse the repository at this point in the history
Instead of exposing the time to establish a connection, the time to upload the
bytes and the time to download the bytes, expose a single time including all
three.

The rational here is, that differentiation of the three is flawed. E.g. when
does one stop the upload timer and start the download timer? When the last byte
is sent? When the last byte is flushed? When the first byte is received?

See libp2p/test-plans#184 (review)
for past discussion.
  • Loading branch information
mxinden authored Jun 23, 2023
1 parent 30ad33c commit a5cd126
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
)

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

func RunClient(addr string, uploadBytes, downloadBytes uint64) error {
Expand All @@ -35,7 +33,6 @@ 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 @@ -47,9 +44,7 @@ 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)))
json, err := json.Marshal(Result{
ConnectionEstablishedSeconds: connectionEstablishmentTook.Seconds(),
UploadSeconds: uploadTook.Seconds(),
DownloadSeconds: downloadTook.Seconds(),
Latency: time.Since(start).Seconds(),
})
if err != nil {
return err
Expand Down

0 comments on commit a5cd126

Please sign in to comment.