tweak: disable bytes pool for socket-proxy and agent
Some checks are pending
Docker Image CI (nightly) / build-nightly (push) Waiting to run
Docker Image CI (nightly) / build-nightly-agent (push) Waiting to run

This commit is contained in:
yusing 2025-05-23 23:01:27 +08:00
parent 0f3b8e68ce
commit 20a1649275
2 changed files with 15 additions and 1 deletions

View file

@ -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()

View file

@ -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.