From 6b34b3f751a42b6f51fef56ac9ba79e0ce20e467 Mon Sep 17 00:00:00 2001 From: Allan Feldman Date: Thu, 26 Aug 2021 11:04:43 -0400 Subject: [PATCH] Verify performance of HTTP TLS mode in benchmarks. --- config/confighttp/confighttp_test.go | 65 ++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 91edc77c3f0..ed5bbeca92b 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -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) + } + }) } + }