mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-01 01:22:34 +02:00
tweak: disable bytes pool for socket-proxy and agent
This commit is contained in:
parent
0f3b8e68ce
commit
20a1649275
2 changed files with 15 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue