diff --git a/internal/utils/synk/pool.go b/internal/utils/synk/pool.go index f9af215..4406f69 100644 --- a/internal/utils/synk/pool.go +++ b/internal/utils/synk/pool.go @@ -19,6 +19,8 @@ const ( mb = 1024 * kb ) +var BytesPoolEnabled = true + const ( InPoolLimit = 32 * mb @@ -43,6 +45,9 @@ func NewBytesPool() *BytesPool { } func (p *BytesPool) Get() []byte { + if !BytesPoolEnabled { + return make([]byte, 0, p.initSize) + } select { case b := <-p.pool: subInPoolSize(int64(cap(b))) @@ -53,7 +58,7 @@ func (p *BytesPool) Get() []byte { } func (p *BytesPool) GetSized(size int) []byte { - if size <= PoolThreshold { + if !BytesPoolEnabled || size <= PoolThreshold { return make([]byte, size) } select { @@ -107,6 +112,10 @@ func init() { defer cleanupTicker.Stop() for { + if !BytesPoolEnabled { + signal.Stop(sigCh) + return + } select { case <-cleanupTicker.C: dropBuffers() diff --git a/socket-proxy/pkg/reverseproxy/reverse_proxy.go b/socket-proxy/pkg/reverseproxy/reverse_proxy.go index b2abaff..0c92ede 100644 --- a/socket-proxy/pkg/reverseproxy/reverse_proxy.go +++ b/socket-proxy/pkg/reverseproxy/reverse_proxy.go @@ -20,9 +20,14 @@ import ( "sync" "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/utils/synk" "golang.org/x/net/http/httpguts" ) +func init() { + synk.BytesPoolEnabled = false +} + // ReverseProxy is an HTTP Handler that takes an incoming request and // sends it to another server, proxying the response back to the // client.