Skip to content

Commit

Permalink
Set the maximum idle connections per host to a large number
Browse files Browse the repository at this point in the history
Ensures we aren't waiting for backend connections
  • Loading branch information
smarterclayton committed Sep 7, 2017
1 parent 9e6cbcb commit 87331e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"strings"
"time"

"golang.org/x/net/http2"

"github.com/18F/hmacauth"
"github.com/openshift/oauth-proxy/cookie"
"github.com/openshift/oauth-proxy/providers"
Expand Down Expand Up @@ -91,11 +93,22 @@ func (u *UpstreamProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
u.handler.ServeHTTP(w, r)
}

func NewReverseProxy(target *url.URL, UpstreamFlush time.Duration) (proxy *httputil.ReverseProxy) {
func NewReverseProxy(target *url.URL, upstreamFlush time.Duration) (proxy *httputil.ReverseProxy) {
proxy = httputil.NewSingleHostReverseProxy(target)
proxy.FlushInterval = UpstreamFlush
proxy.FlushInterval = upstreamFlush

transport := &http.Transport{
MaxIdleConnsPerHost: 500,
IdleConnTimeout: 1 * time.Minute,
}
if err := http2.ConfigureTransport(transport); err != nil {
log.Printf("WARN: Failed to configure http2 transport: %v", err)
}
proxy.Transport = transport

return proxy
}

func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
director := proxy.Director
proxy.Director = func(req *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewOptions() *Options {
ProxyPrefix: "/oauth2",
HttpAddress: "127.0.0.1:4180",
HttpsAddress: ":443",
UpstreamFlush: time.Duration(5)*time.Millisecond,
UpstreamFlush: time.Duration(5) * time.Millisecond,
DisplayHtpasswdForm: true,
CookieName: "_oauth2_proxy",
CookieSecure: true,
Expand Down

0 comments on commit 87331e4

Please sign in to comment.