Closed xipxape closed 3 years ago
@daved I've made the these updates:
@daved In this PR, I'm using the sync/atomic atomic.Value load/store methods. Please compare with the other two PRs I posted:
My next goal is to put the three branches through benchmark testing to compare their performance.
Range: 1.204s - 1.668s Average: 1.385s
10000 135192 ns/op
PASS
ok github.com/OpenEugene/openboard/back/internal/dbg 1.358s
10000 119121 ns/op
PASS
ok github.com/OpenEugene/openboard/back/internal/dbg 1.204s
10000 166115 ns/op
PASS
ok github.com/OpenEugene/openboard/back/internal/dbg 1.668s
10000 127507 ns/op
PASS
ok github.com/OpenEugene/openboard/back/internal/dbg 1.284s
10000 139454 ns/op
PASS
ok github.com/OpenEugene/openboard/back/internal/dbg 1.413s
@daved The benchmark test results show (as you had predicted) that the sync/atomic uint32 implementation has the best performance. I'll label this PR [NOT FOR MERGE] and put #161 up for merge.
After improving benchmark test, I ran test again:
16580 85695 ns/op PASS ok github.com/OpenEugene/openboard/back/internal/dbg 2.157s
$ go test -bench=. goos: linux goarch: amd64 pkg: github.com/OpenEugene/openboard/back/internal/dbg cpu: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz BenchmarkDbgUse-4 4808780 224.6 ns/op BenchmarkDbgUseNil-4 5095231 235.6 ns/op BenchmarkDbgSetAndUse-4 5512214 252.1 ns/op BenchmarkDbgSetAndUseNil-4 22432702 46.82 ns/op PASS ok github.com/OpenEugene/openboard/back/internal/dbg 5.500s
$ go test -bench=. goos: linux goarch: amd64 pkg: github.com/OpenEugene/openboard/back/internal/dbg cpu: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz BenchmarkDbgUse-4 4490373 251.5 ns/op BenchmarkDbgUseNil-4 4580872 251.7 ns/op BenchmarkDbgSetAndUse-4 5409266 207.7 ns/op BenchmarkDbgSetAndUseNil-4 24270432 46.74 ns/op PASS ok github.com/OpenEugene/openboard/back/internal/dbg 5.371s
$ go test -bench=. goos: linux goarch: amd64 pkg: github.com/OpenEugene/openboard/back/internal/dbg cpu: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz BenchmarkDbgUse-4 4613444 256.3 ns/op BenchmarkDbgUseNil-4 4652350 258.5 ns/op BenchmarkDbgSetAndUse-4 5156545 218.9 ns/op BenchmarkDbgSetAndUseNil-4 22653818 49.94 ns/op PASS ok github.com/OpenEugene/openboard/back/internal/dbg 5.493s
$ go test -bench=. goos: linux goarch: amd64 pkg: github.com/OpenEugene/openboard/back/internal/dbg cpu: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz BenchmarkDbgUse-4 4616432 241.4 ns/op BenchmarkDbgUseNil-4 5064988 233.3 ns/op BenchmarkDbgSetAndUse-4 5304114 207.6 ns/op BenchmarkDbgSetAndUseNil-4 24949291 49.70 ns/op PASS ok github.com/OpenEugene/openboard/back/internal/dbg 5.443s
Sync atomic store and load of values seems to beat out mutex locks and unlocks in parallel benchmark tests (PR #162) for the dbg package. I'm recommending this PR for merge.
During our last meeting, @daved found that this debug logger was racy. I fixed it so that race detector did not find a race when I ran go test -bench=. -race
. The fix was not to store the status of the logger with toggle, but rather store the logger itself into an atomic/sync value variable. Here were the results from go test -bench=.
:
goos: linux
goarch: amd64
pkg: github.com/OpenEugene/openboard/back/internal/dbg
cpu: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz
BenchmarkDbgUse-4 4487584 246.4 ns/op
BenchmarkDbgUseNil-4 4612100 248.8 ns/op
BenchmarkDbgSetAndUse-4 4194343 249.5 ns/op
BenchmarkDbgSetAndUseNil-4 22563385 47.44 ns/op
PASS
ok github.com/OpenEugene/openboard/back/internal/dbg 5.301s
The performance using sync atomic still beats the mutex version in PR #162. I maintain my recommendation that this is the dbg logger version that gets merged.
Added ability to log information to stdout, errors to stderr, and uses package-level variable debug logger for debugging.
Closes #123