Go - Structured Logging Benchmark
by Magazine zum Globus
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.- Average and total time of execution (by operation).
- 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. You can enable multiple loggers by specifying multiple flags:-l zerolog -l zap -l logrus
.-o <operation>
: enables an operation. You can enable multiple operations by specifying multiple flags:-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 interval
-
- Define the logger in a sub-package.
-
- Provide a
Setup() benchmark.Setup
function in your logger's sub-package.
- Provide a
-
- Implement all benchmark operations:
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)
-
- Add your setup to
setups
.
- Add your setup to
-
- Run the tests with
go test -v -race ./...
and make sure everything's working.
- Run the tests with