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