mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
perf: reuse reverse proxy copy buffers
This commit is contained in:
parent
efa1e3fb3f
commit
71a344a3de
4 changed files with 282 additions and 3 deletions
|
|
@ -84,6 +84,13 @@ type reverseProxyHandler struct {
|
|||
roundRobin atomic.Uint64
|
||||
}
|
||||
|
||||
var reverseProxyCopyBufferPool = sync.Pool{
|
||||
New: func() any {
|
||||
buf := make([]byte, 32*1024)
|
||||
return &buf
|
||||
},
|
||||
}
|
||||
|
||||
type reverseProxyStatusError struct {
|
||||
status int
|
||||
err error
|
||||
|
|
@ -1153,6 +1160,10 @@ func (p *reverseProxyHandler) copyResponse(dst ResponseWriter, src io.Reader, fl
|
|||
if p.config.BufferPool != nil {
|
||||
buf = p.config.BufferPool.Get()
|
||||
defer p.config.BufferPool.Put(buf)
|
||||
} else {
|
||||
bufp := reverseProxyCopyBufferPool.Get().(*[]byte)
|
||||
buf = *bufp
|
||||
defer reverseProxyCopyBufferPool.Put(bufp)
|
||||
}
|
||||
_, err := p.copyBuffer(writer, src, buf)
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue