diff --git a/perf/impl/go-libp2p/v0.27/main.go b/perf/impl/go-libp2p/v0.27/main.go index cd05a205e..ad7ad1ea6 100644 --- a/perf/impl/go-libp2p/v0.27/main.go +++ b/perf/impl/go-libp2p/v0.27/main.go @@ -89,7 +89,10 @@ func main() { } jsonB, err := json.Marshal(Result{ - Latency: time.Since(start).Seconds(), + TimeSeconds: time.Since(start).Seconds(), + UploadBytes: *uploadBytes, + DownloadBytes: *downloadBytes, + Type: "final", }) if err != nil { log.Fatalf("failed to marshal perf result: %s", err) @@ -99,7 +102,10 @@ func main() { } type Result struct { - Latency float64 `json:"latency"` + Type string `json:"type"` + TimeSeconds float64 `json:"timeSeconds"` + UploadBytes uint64 `json:"uploadBytes"` + DownloadBytes uint64 `json:"downloadBytes"` } type simpleReader struct { diff --git a/perf/impl/go-libp2p/v0.27/perf.go b/perf/impl/go-libp2p/v0.27/perf.go index 55f8ad38b..29ff58326 100644 --- a/perf/impl/go-libp2p/v0.27/perf.go +++ b/perf/impl/go-libp2p/v0.27/perf.go @@ -3,8 +3,10 @@ package main import ( "context" "encoding/binary" + "encoding/json" "fmt" "io" + "time" logging "github.com/ipfs/go-log/v2" pool "github.com/libp2p/go-buffer-pool" @@ -89,7 +91,26 @@ func sendBytes(s io.Writer, bytesToSend uint64) error { buf := pool.Get(blockSize) defer pool.Put(buf) + lastReportTime := time.Now() + lastReportWrite := uint64(0) + for bytesToSend > 0 { + now := time.Now() + if now.Sub(lastReportTime) >= time.Second { + jsonB, err := json.Marshal(Result{ + TimeSeconds: now.Sub(lastReportTime).Seconds(), + UploadBytes: lastReportWrite, + Type: "intermediary", + }) + if err != nil { + log.Fatalf("failed to marshal perf result: %s", err) + } + fmt.Println(string(jsonB)) + + lastReportTime = now + lastReportWrite = 0 + } + toSend := buf if bytesToSend < blockSize { toSend = buf[:bytesToSend] @@ -100,15 +121,49 @@ func sendBytes(s io.Writer, bytesToSend uint64) error { return err } bytesToSend -= uint64(n) + lastReportWrite += uint64(n) } return nil } func drainStream(s io.Reader) (uint64, error) { var recvd int64 - recvd, err := io.Copy(io.Discard, s) + recvd, err := io.Copy(io.Discard, &reportingReader{orig: s, LastReportTime: time.Now()}) if err != nil && err != io.EOF { return uint64(recvd), err } return uint64(recvd), nil } + +type reportingReader struct { + orig io.Reader + LastReportTime time.Time + lastReportRead uint64 +} + +var _ io.Reader = &reportingReader{} + +func (r *reportingReader) Read(b []byte) (int, error) { + n, err := r.orig.Read(b) + r.lastReportRead += uint64(n) + + now := time.Now() + if now.Sub(r.LastReportTime) >= time.Second { + result := Result{ + TimeSeconds: now.Sub(r.LastReportTime).Seconds(), + Type: "intermediary", + DownloadBytes: r.lastReportRead, + } + + jsonB, err := json.Marshal(result) + if err != nil { + log.Fatalf("failed to marshal perf result: %s", err) + } + fmt.Println(string(jsonB)) + + r.LastReportTime = now + r.lastReportRead = 0 + } + + return n, err +} diff --git a/perf/impl/go-libp2p/v0.28/main.go b/perf/impl/go-libp2p/v0.28/main.go index cd05a205e..ad7ad1ea6 100644 --- a/perf/impl/go-libp2p/v0.28/main.go +++ b/perf/impl/go-libp2p/v0.28/main.go @@ -89,7 +89,10 @@ func main() { } jsonB, err := json.Marshal(Result{ - Latency: time.Since(start).Seconds(), + TimeSeconds: time.Since(start).Seconds(), + UploadBytes: *uploadBytes, + DownloadBytes: *downloadBytes, + Type: "final", }) if err != nil { log.Fatalf("failed to marshal perf result: %s", err) @@ -99,7 +102,10 @@ func main() { } type Result struct { - Latency float64 `json:"latency"` + Type string `json:"type"` + TimeSeconds float64 `json:"timeSeconds"` + UploadBytes uint64 `json:"uploadBytes"` + DownloadBytes uint64 `json:"downloadBytes"` } type simpleReader struct { diff --git a/perf/impl/go-libp2p/v0.28/perf.go b/perf/impl/go-libp2p/v0.28/perf.go index 55f8ad38b..29ff58326 100644 --- a/perf/impl/go-libp2p/v0.28/perf.go +++ b/perf/impl/go-libp2p/v0.28/perf.go @@ -3,8 +3,10 @@ package main import ( "context" "encoding/binary" + "encoding/json" "fmt" "io" + "time" logging "github.com/ipfs/go-log/v2" pool "github.com/libp2p/go-buffer-pool" @@ -89,7 +91,26 @@ func sendBytes(s io.Writer, bytesToSend uint64) error { buf := pool.Get(blockSize) defer pool.Put(buf) + lastReportTime := time.Now() + lastReportWrite := uint64(0) + for bytesToSend > 0 { + now := time.Now() + if now.Sub(lastReportTime) >= time.Second { + jsonB, err := json.Marshal(Result{ + TimeSeconds: now.Sub(lastReportTime).Seconds(), + UploadBytes: lastReportWrite, + Type: "intermediary", + }) + if err != nil { + log.Fatalf("failed to marshal perf result: %s", err) + } + fmt.Println(string(jsonB)) + + lastReportTime = now + lastReportWrite = 0 + } + toSend := buf if bytesToSend < blockSize { toSend = buf[:bytesToSend] @@ -100,15 +121,49 @@ func sendBytes(s io.Writer, bytesToSend uint64) error { return err } bytesToSend -= uint64(n) + lastReportWrite += uint64(n) } return nil } func drainStream(s io.Reader) (uint64, error) { var recvd int64 - recvd, err := io.Copy(io.Discard, s) + recvd, err := io.Copy(io.Discard, &reportingReader{orig: s, LastReportTime: time.Now()}) if err != nil && err != io.EOF { return uint64(recvd), err } return uint64(recvd), nil } + +type reportingReader struct { + orig io.Reader + LastReportTime time.Time + lastReportRead uint64 +} + +var _ io.Reader = &reportingReader{} + +func (r *reportingReader) Read(b []byte) (int, error) { + n, err := r.orig.Read(b) + r.lastReportRead += uint64(n) + + now := time.Now() + if now.Sub(r.LastReportTime) >= time.Second { + result := Result{ + TimeSeconds: now.Sub(r.LastReportTime).Seconds(), + Type: "intermediary", + DownloadBytes: r.lastReportRead, + } + + jsonB, err := json.Marshal(result) + if err != nil { + log.Fatalf("failed to marshal perf result: %s", err) + } + fmt.Println(string(jsonB)) + + r.LastReportTime = now + r.lastReportRead = 0 + } + + return n, err +} diff --git a/perf/impl/go-libp2p/v0.31/main.go b/perf/impl/go-libp2p/v0.31/main.go index cd05a205e..ad7ad1ea6 100644 --- a/perf/impl/go-libp2p/v0.31/main.go +++ b/perf/impl/go-libp2p/v0.31/main.go @@ -89,7 +89,10 @@ func main() { } jsonB, err := json.Marshal(Result{ - Latency: time.Since(start).Seconds(), + TimeSeconds: time.Since(start).Seconds(), + UploadBytes: *uploadBytes, + DownloadBytes: *downloadBytes, + Type: "final", }) if err != nil { log.Fatalf("failed to marshal perf result: %s", err) @@ -99,7 +102,10 @@ func main() { } type Result struct { - Latency float64 `json:"latency"` + Type string `json:"type"` + TimeSeconds float64 `json:"timeSeconds"` + UploadBytes uint64 `json:"uploadBytes"` + DownloadBytes uint64 `json:"downloadBytes"` } type simpleReader struct { diff --git a/perf/impl/go-libp2p/v0.31/perf.go b/perf/impl/go-libp2p/v0.31/perf.go index 55f8ad38b..29ff58326 100644 --- a/perf/impl/go-libp2p/v0.31/perf.go +++ b/perf/impl/go-libp2p/v0.31/perf.go @@ -3,8 +3,10 @@ package main import ( "context" "encoding/binary" + "encoding/json" "fmt" "io" + "time" logging "github.com/ipfs/go-log/v2" pool "github.com/libp2p/go-buffer-pool" @@ -89,7 +91,26 @@ func sendBytes(s io.Writer, bytesToSend uint64) error { buf := pool.Get(blockSize) defer pool.Put(buf) + lastReportTime := time.Now() + lastReportWrite := uint64(0) + for bytesToSend > 0 { + now := time.Now() + if now.Sub(lastReportTime) >= time.Second { + jsonB, err := json.Marshal(Result{ + TimeSeconds: now.Sub(lastReportTime).Seconds(), + UploadBytes: lastReportWrite, + Type: "intermediary", + }) + if err != nil { + log.Fatalf("failed to marshal perf result: %s", err) + } + fmt.Println(string(jsonB)) + + lastReportTime = now + lastReportWrite = 0 + } + toSend := buf if bytesToSend < blockSize { toSend = buf[:bytesToSend] @@ -100,15 +121,49 @@ func sendBytes(s io.Writer, bytesToSend uint64) error { return err } bytesToSend -= uint64(n) + lastReportWrite += uint64(n) } return nil } func drainStream(s io.Reader) (uint64, error) { var recvd int64 - recvd, err := io.Copy(io.Discard, s) + recvd, err := io.Copy(io.Discard, &reportingReader{orig: s, LastReportTime: time.Now()}) if err != nil && err != io.EOF { return uint64(recvd), err } return uint64(recvd), nil } + +type reportingReader struct { + orig io.Reader + LastReportTime time.Time + lastReportRead uint64 +} + +var _ io.Reader = &reportingReader{} + +func (r *reportingReader) Read(b []byte) (int, error) { + n, err := r.orig.Read(b) + r.lastReportRead += uint64(n) + + now := time.Now() + if now.Sub(r.LastReportTime) >= time.Second { + result := Result{ + TimeSeconds: now.Sub(r.LastReportTime).Seconds(), + Type: "intermediary", + DownloadBytes: r.lastReportRead, + } + + jsonB, err := json.Marshal(result) + if err != nil { + log.Fatalf("failed to marshal perf result: %s", err) + } + fmt.Println(string(jsonB)) + + r.LastReportTime = now + r.lastReportRead = 0 + } + + return n, err +} diff --git a/perf/runner/src/versions.ts b/perf/runner/src/versions.ts index 879554f09..2383ca2cd 100644 --- a/perf/runner/src/versions.ts +++ b/perf/runner/src/versions.ts @@ -20,11 +20,26 @@ export const versions: Array = [ implementation: "https", transportStacks: ["tcp"] }, + { + id: "v0.27", + implementation: "go-libp2p", + transportStacks: ["tcp", "quic-v1"] + }, + { + id: "v0.28", + implementation: "go-libp2p", + transportStacks: ["tcp", "quic-v1"] + }, { id: "v0.29", implementation: "go-libp2p", transportStacks: ["tcp", "quic-v1"] }, + { + id: "v0.31", + implementation: "go-libp2p", + transportStacks: ["tcp", "quic-v1"] + }, // { // id: "v0.46", // implementation: "js-libp2p",