From dc450dcf83eaac2f94e71bf8457c00cc91017fb4 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 22 Aug 2022 18:02:44 +0300 Subject: [PATCH] quic: increase the buffer size used for encoding qlogs --- p2p/transport/quic/tracer.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/p2p/transport/quic/tracer.go b/p2p/transport/quic/tracer.go index c5bbf71493..74a5e36b49 100644 --- a/p2p/transport/quic/tracer.go +++ b/p2p/transport/quic/tracer.go @@ -62,7 +62,9 @@ func newQlogger(qlogDir string, role logging.Perspective, connID []byte) io.Writ return &qlogger{ f: f, filename: finalFilename, - Writer: bufio.NewWriter(f), + // The size of a qlog file for a raw file download is ~2/3 of the amount of data transferred. + // bufio.NewWriter creates a buffer with a buffer of only 4 kB, leading to a large number of syscalls. + Writer: bufio.NewWriterSize(f, 128<<10), } } @@ -80,7 +82,7 @@ func (l *qlogger) Close() error { return err } defer f.Close() - buf := bufio.NewWriter(f) + buf := bufio.NewWriterSize(f, 128<<10) c, err := zstd.NewWriter(buf, zstd.WithEncoderLevel(zstd.SpeedFastest), zstd.WithWindowSize(32*1024)) if err != nil { return err