diff --git a/pkg/log/config.go b/pkg/log/config.go index b6cf37945d..a43e16a120 100644 --- a/pkg/log/config.go +++ b/pkg/log/config.go @@ -153,7 +153,7 @@ func (cfg *Config) initialize() { cfg.AsyncWritePendingLength = 1024 } if cfg.AsyncWriteBufferSize <= 0 { - cfg.AsyncWriteBufferSize = 1024 * 1024 + cfg.AsyncWriteBufferSize = 4 * 1024 } if cfg.AsyncWriteMaxBytesPerLog <= 0 { cfg.AsyncWriteMaxBytesPerLog = 1024 * 1024 diff --git a/pkg/util/paramtable/component_param.go b/pkg/util/paramtable/component_param.go index b0fad0da66..073f9e6533 100644 --- a/pkg/util/paramtable/component_param.go +++ b/pkg/util/paramtable/component_param.go @@ -1675,11 +1675,14 @@ The larger the pending length, the more memory is used, the less logging writes l.AsyncWriteBufferSize = ParamItem{ Key: "log.asyncWrite.bufferSize", - DefaultValue: "1m", + DefaultValue: "4k", Version: "2.6.7", Doc: `The buffer size of the underlying bufio writer. The larger the buffer size, the more memory is used, -but the less the number of writes to the underlying file system.`, +but the less the number of writes to the underlying file system. +Because the cpp will print the log message into stdout, +when the logging is woring with pipe like tty/docker log driver/k8s, +PIPE_BUF=4096 may interleave the go log and cpp log together, so 4kb is set as default value to avoid this.`, Export: false, } l.AsyncWriteBufferSize.Init(base.mgr) diff --git a/pkg/util/paramtable/component_param_test.go b/pkg/util/paramtable/component_param_test.go index 53bbc5964f..8c117292c8 100644 --- a/pkg/util/paramtable/component_param_test.go +++ b/pkg/util/paramtable/component_param_test.go @@ -163,7 +163,7 @@ func TestComponentParam(t *testing.T) { assert.Equal(t, "error", Params.AsyncWriteNonDroppableLevel.GetValue()) assert.Equal(t, 1*time.Second, Params.AsyncWriteStopTimeout.GetAsDurationByParse()) assert.Equal(t, 1024, Params.AsyncWritePendingLength.GetAsInt()) - assert.Equal(t, int64(1024*1024), Params.AsyncWriteBufferSize.GetAsSize()) + assert.Equal(t, int64(4*1024), Params.AsyncWriteBufferSize.GetAsSize()) assert.Equal(t, int64(1024*1024), Params.AsyncWriteMaxBytesPerLog.GetAsSize()) })