Skip to content

Commit

Permalink
Verify performance of HTTP TLS mode in benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-feld committed Aug 26, 2021
1 parent a040e72 commit 6b34b3f
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,20 +628,57 @@ func TestHttpHeaders(t *testing.T) {

func BenchmarkHttpRequest(b *testing.B) {

hss := &HTTPServerSettings{
Endpoint: "localhost:0",
tests := []struct {
name string
tlsServerCreds *configtls.TLSServerSetting
tlsClientCreds *configtls.TLSClientSetting
hasError bool
}{
{
name: "noTLS",
tlsServerCreds: nil,
tlsClientCreds: &configtls.TLSClientSetting{
Insecure: true,
},
},
{
name: "TLS",
tlsServerCreds: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CAFile: path.Join(".", "testdata", "ca.crt"),
CertFile: path.Join(".", "testdata", "server.crt"),
KeyFile: path.Join(".", "testdata", "server.key"),
},
},
tlsClientCreds: &configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
CAFile: path.Join(".", "testdata", "ca.crt"),
},
ServerName: "localhost",
},
},
}
s := hss.ToServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, errWrite := fmt.Fprint(w, "test")
assert.NoError(b, errWrite)
}))

// Use the handler generated by ToServer for benchmarking
// to avoid network artifacts
req := httptest.NewRequest("GET", "/", nil)

for i := 0; i < b.N; i++ {
rw := httptest.NewRecorder()
s.Handler.ServeHTTP(rw, req)

for _, bb := range tests {
b.Run(bb.name, func(b *testing.B) {
hss := &HTTPServerSettings{
Endpoint: "localhost:0",
TLSSetting: bb.tlsServerCreds,
}
s := hss.ToServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, errWrite := fmt.Fprint(w, "test")
assert.NoError(b, errWrite)
}))

// Use the handler generated by ToServer for benchmarking
// to avoid network artifacts
req := httptest.NewRequest("GET", "/", nil)

for i := 0; i < b.N; i++ {
rw := httptest.NewRecorder()
s.Handler.ServeHTTP(rw, req)
}
})
}

}

0 comments on commit 6b34b3f

Please sign in to comment.