Structured JSON logging Go libraries benchmark
A structured JSON logging performance benchmark providing realistic performance metrics for the latest versions of:
Performance is measured by the following main criteria:
total alloc
- Total size of allocated memory.num-gc
- Total number of GC cycles.mallocs
- Total number of allocated heap objects.total pause
- Total duration of GC pauses.
i7-8569U @ 2.80GHz
Install the benchmark:
go get github.com/globusdigital/logbench
Run it:
logbench -w 8 -t 1_000_000 -o_all -l zerolog
-w <num>
: defines the number of concurrently writing goroutines.-l <logger>
: enables a logger.-l zerolog -l zap -l logrus
.-o <operation>
: enables an operation.-o info -o error -o info_with_3
.-t <num>
: defines the number of logs to be written for each operation.-o_all
: enables all operations ignoring all specified -o
flags-memprof <path>
: specifies the output file path for the memory profile (disabled when not set)-mi <duration>
: memory inspection intervalSetup() benchmark.Setup
function in your logger’s sub-package.FnInfo func(msg string)
FnInfoFmt func(msg string, data int)
FnError func(msg string)
FnInfoWithErrorStack func(msg string, err error)
FnInfoWith3 func(msg string, fields *benchmark.Fields3)
FnInfoWith10 func(msg string, fields *benchmark.Fields10)
FnInfoWith10Exist func(msg string)
setups
.go test -v -race ./...
and make sure everything’s working.