From b791bb6cdf470ad08e2d32dc5a7211922948a9c4 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 3 Jan 2023 17:17:06 +1300 Subject: [PATCH 1/2] add a benchmark integration test for performing handshakes --- integrationtests/self/benchmark_test.go | 45 ++++++++++++++++++++++++ integrationtests/self/self_suite_test.go | 8 ++--- 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 integrationtests/self/benchmark_test.go diff --git a/integrationtests/self/benchmark_test.go b/integrationtests/self/benchmark_test.go new file mode 100644 index 00000000..9030e8bf --- /dev/null +++ b/integrationtests/self/benchmark_test.go @@ -0,0 +1,45 @@ +package self_test + +import ( + "context" + "net" + "testing" + + "github.com/quic-go/quic-go" +) + +func BenchmarkHandshake(b *testing.B) { + b.ReportAllocs() + + ln, err := quic.ListenAddr("localhost:0", tlsConfig, nil) + if err != nil { + b.Fatal(err) + } + defer ln.Close() + + connChan := make(chan quic.Connection, 1) + go func() { + for { + conn, err := ln.Accept(context.Background()) + if err != nil { + return + } + connChan <- conn + } + }() + + conn, err := net.ListenUDP("udp", nil) + if err != nil { + b.Fatal(err) + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + c, err := quic.Dial(conn, ln.Addr(), "localhost", tlsClientConfig, nil) + if err != nil { + b.Fatal(err) + } + <-connChan + c.CloseWithError(0, "") + } +} diff --git a/integrationtests/self/self_suite_test.go b/integrationtests/self/self_suite_test.go index 85955546..943b8753 100644 --- a/integrationtests/self/self_suite_test.go +++ b/integrationtests/self/self_suite_test.go @@ -106,10 +106,6 @@ var ( func init() { flag.StringVar(&logFileName, "logfile", "", "log file") flag.BoolVar(&enableQlog, "qlog", false, "enable qlog") -} - -var _ = BeforeSuite(func() { - mrand.Seed(GinkgoRandomSeed()) ca, caPrivateKey, err := generateCA() if err != nil { @@ -138,6 +134,10 @@ var _ = BeforeSuite(func() { RootCAs: root, NextProtos: []string{alpn}, } +} + +var _ = BeforeSuite(func() { + mrand.Seed(GinkgoRandomSeed()) if enableQlog { quicConfigTracer = qlog.NewTracer(func(p logging.Perspective, connectionID []byte) io.WriteCloser { From 97dae87bf4ceb11d98ff6c192e93c51ba820e067 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 4 Feb 2023 18:42:49 +1300 Subject: [PATCH 2/2] add a benchmark allocation test for opening / accepting streams --- integrationtests/self/benchmark_test.go | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/integrationtests/self/benchmark_test.go b/integrationtests/self/benchmark_test.go index 9030e8bf..eaab654a 100644 --- a/integrationtests/self/benchmark_test.go +++ b/integrationtests/self/benchmark_test.go @@ -2,6 +2,7 @@ package self_test import ( "context" + "fmt" "net" "testing" @@ -43,3 +44,49 @@ func BenchmarkHandshake(b *testing.B) { c.CloseWithError(0, "") } } + +func BenchmarkStreamChurn(b *testing.B) { + b.ReportAllocs() + + ln, err := quic.ListenAddr("localhost:0", tlsConfig, &quic.Config{MaxIncomingStreams: 1e10}) + if err != nil { + b.Fatal(err) + } + defer ln.Close() + + errChan := make(chan error, 1) + go func() { + conn, err := ln.Accept(context.Background()) + if err != nil { + errChan <- err + return + } + close(errChan) + for { + str, err := conn.AcceptStream(context.Background()) + if err != nil { + return + } + str.Close() + } + }() + + c, err := quic.DialAddr(fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port), tlsClientConfig, nil) + if err != nil { + b.Fatal(err) + } + if err := <-errChan; err != nil { + b.Fatal(err) + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + str, err := c.OpenStreamSync(context.Background()) + if err != nil { + b.Fatal(err) + } + if err := str.Close(); err != nil { + b.Fatal(err) + } + } +}