Skip to content

Commit

Permalink
increase buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
maciuszek committed Jan 9, 2025
1 parent 7d38863 commit bab7ed4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (

flushInterval = 2 * time.Second
logOnEveryNDroppedBytes = 1 << 15 // Log once per 32kb of dropped stats
defaultBufferSizeTCP = 1 << 16
defaultBufferSizeTCP = 1 << 16 * 2

// 1432 bytes is optimal for regular networks with an MTU of 1500 and
// is to prevent fragmenting UDP datagrams
Expand Down Expand Up @@ -111,14 +111,17 @@ func NewNetSink(opts ...SinkOption) FlushableSink {
// Calculate buffer size based on protocol, for UDP we want to pick a
// buffer size that will prevent datagram fragmentation.
var bufSize int
var queueSize int
switch s.conf.StatsdProtocol {
case "udp", "udp4", "udp6":
bufSize = defaultBufferSizeUDP
queueSize = approxMaxMemBytes / bufSize
default:
bufSize = defaultBufferSizeTCP
queueSize = (approxMaxMemBytes * 2) / bufSize
}

s.outc = make(chan *bytes.Buffer, approxMaxMemBytes/bufSize)
s.outc = make(chan *bytes.Buffer, queueSize)
s.retryc = make(chan *bytes.Buffer, 1) // It should be okay to limit this given we preferentially process from this over outc.

writer := &sinkWriter{outc: s.outc}
Expand Down

0 comments on commit bab7ed4

Please sign in to comment.