https://github.com/globusdigital/logbench
Structured JSON logging Go libraries benchmark
https://github.com/globusdigital/logbench
benchmark go golang logging zap zerolog
Last synced: 5 months ago
JSON representation
Structured JSON logging Go libraries benchmark
- Host: GitHub
- URL: https://github.com/globusdigital/logbench
- Owner: globusdigital
- License: bsd-3-clause
- Created: 2019-11-08T14:47:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T08:36:08.000Z (over 3 years ago)
- Last Synced: 2024-06-19T03:08:22.351Z (about 2 years ago)
- Topics: benchmark, go, golang, logging, zap, zerolog
- Language: Go
- Homepage:
- Size: 545 KB
- Stars: 22
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go - Structured Logging Benchmark
by Magazine zum Globus
A structured JSON logging performance benchmark providing realistic performance metrics for the latest versions of:
- [sirupsen/logrus](https://github.com/sirupsen/logrus)
- [uber/zap](https://github.com/uber-go/zap)
- [rs/zerolog](https://github.com/rs/zerolog)
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).

_i7-8569U @ 2.80GHz_
## Getting started
1. Install the benchmark:
```
go get github.com/globusdigital/logbench
```
2. Run it:
```
logbench -w 8 -t 1_000_000 -o_all -l zerolog
```
- `-w `: defines the number of concurrently writing goroutines.
- `-l `: enables a logger.
You can enable multiple loggers by specifying multiple flags: `-l zerolog -l zap -l logrus`.
- `-o `: enables an operation.
You can enable multiple operations by specifying multiple flags: `-o info -o error -o info_with_3`.
- `-t `: defines the number of logs to be written for each operation.
- `-o_all`: enables all operations ignoring all specified `-o` flags
- `-memprof `: specifies the output file path for the memory profile (disabled when not set)
- `-mi `: memory inspection interval
## How-to
### Adding a new logger to the benchmark
- 1. Define the logger in a sub-package.
- 2. Provide a `Setup() benchmark.Setup` function in your logger's sub-package.
- 3. 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)`
- 4. Add your setup to [`setups`](https://github.com/globusdigital/logbench/blob/eff659cfb1eb06b1d139db6735b2b2ce6944632c/main.go#L21).
- 5. Run the tests with `go test -v -race ./...` and make sure everything's working.