Merge pull request #3697 from quic-go/benchmark-integration

add a benchmark integration tests to measure allocations
This commit is contained in:
Marten Seemann 2023-03-27 00:53:12 +11:00 committed by GitHub
commit 4612b3f19f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 4 deletions

View file

@ -0,0 +1,92 @@
package self_test
import (
"context"
"fmt"
"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, "")
}
}
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)
}
}
}

View file

@ -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 {