go-graphite / carbon-clickhouse

Graphite metrics receiver with ClickHouse as storage
MIT License
186 stars 47 forks source link

receiver: minimized allocations in Base.PlainParseLine and one-pass escape #76

Closed msaf1980 closed 3 years ago

msaf1980 commented 3 years ago

Some perfomance optimizations for receiver: 1) One pass escape with direct write

BenchmarkGraphite-6       861072          1325 ns/op         288 B/op          3 allocs/op
BenchmarkGraphiteEscaped-6        781430          1446 ns/op         592 B/op          4 allocs/op

Original version

BenchmarkGraphite-6       750898          1505 ns/op         544 B/op          6 allocs/op
BenchmarkGraphiteEscaped-6        631176          1697 ns/op         613 B/op          8 allocs/op

2) Convert string to []bytes with unsafe method (no allocation)

BenchmarkPlainParseBuffer-6      7500656           157 ns/op           0 B/op          0 allocs/op

Original version


BenchmarkPlainParseBuffer-6      5230838           200 ns/op          48 B/op          1 allocs/op
Felixoid commented 3 years ago

As far as I got, here instead of strings now something like a memory-efficient buffer is used. Am I right?

Unfortunately, we don't use the tags, so I can't check if it works. Would be nice to get some approves if somebody uses it.

msaf1980 commented 3 years ago

As far as I got, here instead of strings now something like a memory-efficient buffer is used. Am I right?

Unfortunately, we don't use the tags, so I can't check if it works. Would be nice to get some approves if somebody uses it.

Yes. And reduce allocation during string to bytes conversion. I'll use this in our production environment.