Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: compress kept trace decision message (#1430)
## Which problem is this PR solving? Due to the multiplication effect of pubsub messages through Redis, we would like to bring down the amount of network traffic sent by Redis. One of the biggest contributors is `TraceDecison` message used to communicate kept trace decisions. This PR uses `snappy` to compress the data and then encoded using `gob` Here's the benchmark results comparing to the original JSON encoding. In the `BenchmarkCompressionSizes` test, I generated a batch of 1000 trace decisions as the input. The amount of decrease in data size is 90% ``` goos: darwin goarch: arm64 pkg: github.com/honeycombio/refinery/collect cpu: Apple M2 Max BenchmarkDynamicJSONEncoding-12 3139 353164 ns/op 443032 B/op 3 allocs/op BenchmarkDynamicCompressedEncoding-12 3050 383788 ns/op 475333 B/op 62 allocs/op BenchmarkDynamicJSONDecoding-12 561 2114997 ns/op 590167 B/op 5018 allocs/op BenchmarkDynamicCompressedDecoding-12 3285 360892 ns/op 445667 B/op 5244 allocs/op BenchmarkCompressionSizes/JSON_Encoding-12 5000 238046 ns/op 164091 B/op 2 allocs/op --- BENCH: BenchmarkCompressionSizes/JSON_Encoding-12 trace_decision_test.go:305: JSON Encoding: Total Batch: 1, Total Size: 160671 bytes, Average Size: 160671.00 bytes trace_decision_test.go:305: JSON Encoding: Total Batch: 100, Total Size: 16227771 bytes, Average Size: 162277.71 bytes trace_decision_test.go:305: JSON Encoding: Total Batch: 5000, Total Size: 819582771 bytes, Average Size: 163916.55 bytes BenchmarkCompressionSizes/Snappy_Compression-12 5052 236998 ns/op 299547 B/op 59 allocs/op --- BENCH: BenchmarkCompressionSizes/Snappy_Compression-12 trace_decision_test.go:319: Snappy Compression: Total Batch: 1, Total Size: 12115 bytes, Average Size: 12115.00 bytes trace_decision_test.go:319: Snappy Compression: Total Batch: 100, Total Size: 1223615 bytes, Average Size: 12236.15 bytes trace_decision_test.go:319: Snappy Compression: Total Batch: 5052, Total Size: 62428595 bytes, Average Size: 12357.20 bytes ``` I also used `sync.Pool` for both compression and decompression buffers as well as `snappy.Writer` to reduce allocation --------- Co-authored-by: Mike Goldsmith <[email protected]> Co-authored-by: Kent Quirk <[email protected]>
- Loading branch information