Handle buffer pool for oxy
This commit is contained in:
parent
446d73fcf5
commit
62ded580ce
4 changed files with 44 additions and 1 deletions
27
server/bufferpool.go
Normal file
27
server/bufferpool.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package server
|
||||
|
||||
import "sync"
|
||||
|
||||
const bufferPoolSize int = 32 * 1024
|
||||
|
||||
func newBufferPool() *bufferPool {
|
||||
return &bufferPool{
|
||||
pool: sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, bufferPoolSize)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type bufferPool struct {
|
||||
pool sync.Pool
|
||||
}
|
||||
|
||||
func (b *bufferPool) Get() []byte {
|
||||
return b.pool.Get().([]byte)
|
||||
}
|
||||
|
||||
func (b *bufferPool) Put(bytes []byte) {
|
||||
b.pool.Put(bytes)
|
||||
}
|
|
@ -11,6 +11,7 @@ import (
|
|||
stdlog "log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -75,6 +76,7 @@ type Server struct {
|
|||
metricsRegistry metrics.Registry
|
||||
provider provider.Provider
|
||||
configurationListeners []func(types.Configuration)
|
||||
bufferPool httputil.BufferPool
|
||||
}
|
||||
|
||||
type serverEntryPoints map[string]*serverEntryPoint
|
||||
|
@ -106,6 +108,8 @@ func NewServer(globalConfiguration configuration.GlobalConfiguration, provider p
|
|||
server.globalConfiguration.API.CurrentConfigurations = &server.currentConfigurations
|
||||
}
|
||||
|
||||
server.bufferPool = newBufferPool()
|
||||
|
||||
server.routinesPool = safe.NewPool(context.Background())
|
||||
server.defaultForwardingRoundTripper = createHTTPTransport(globalConfiguration)
|
||||
|
||||
|
@ -1001,6 +1005,7 @@ func (s *Server) loadConfig(configurations types.Configurations, globalConfigura
|
|||
forward.ErrorHandler(errorHandler),
|
||||
forward.Rewriter(rewriter),
|
||||
forward.ResponseModifier(responseModifier),
|
||||
forward.BufferPool(s.bufferPool),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue