Skip to content

Commit 9cde11f

Browse files
committed
TUN-6038: Reduce buffer size used for proxying data
The buffer size was big to support a compression feature that we don't use anymore. As such, we can now reduce this and be more efficient with memory usage.
1 parent d1a4710 commit 9cde11f

File tree

2 files changed

+2
-36
lines changed

2 files changed

+2
-36
lines changed

proxy/pool.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

proxy/proxy.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/rs/zerolog"
1313

1414
"github.com/cloudflare/cloudflared/carrier"
15+
"github.com/cloudflare/cloudflared/cfio"
1516
"github.com/cloudflare/cloudflared/connection"
1617
"github.com/cloudflare/cloudflared/ingress"
1718
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
@@ -32,7 +33,6 @@ type Proxy struct {
3233
warpRouting *ingress.WarpRoutingService
3334
tags []tunnelpogs.Tag
3435
log *zerolog.Logger
35-
bufferPool *bufferPool
3636
}
3737

3838
// NewOriginProxy returns a new instance of the Proxy struct.
@@ -46,7 +46,6 @@ func NewOriginProxy(
4646
ingressRules: ingressRules,
4747
tags: tags,
4848
log: log,
49-
bufferPool: newBufferPool(512 * 1024),
5049
}
5150
if warpRoutingEnabled {
5251
proxy.warpRouting = ingress.NewWarpRoutingService()
@@ -218,11 +217,7 @@ func (p *Proxy) proxyHTTPRequest(
218217
p.log.Debug().Msg("Detected Server-Side Events from Origin")
219218
p.writeEventStream(w, resp.Body)
220219
} else {
221-
// Use CopyBuffer, because Copy only allocates a 32KiB buffer, and cross-stream
222-
// compression generates dictionary on first write
223-
buf := p.bufferPool.Get()
224-
defer p.bufferPool.Put(buf)
225-
_, _ = io.CopyBuffer(w, resp.Body, buf)
220+
_, _ = cfio.Copy(w, resp.Body)
226221
}
227222

228223
p.logOriginResponse(resp, fields)

0 commit comments

Comments
 (0)