smira / go-statsd

Go statsd client library with zero allocation overhead, great performance and reconnects
MIT License
109 stars 18 forks source link

Refactor the way full packets are detected #3

Closed smira closed 6 years ago

smira commented 6 years ago

Client was trying to estimate size of the next metric before actually producing it to guess whether next metric is going to overflow the buffer, which has never been easy nor precise.

Refactor that code to always append metric first, and check for overflow next. When overflow happens, slice part before overflow for deliver and save tail to be initial content of the next buffer.

The price is extra 1K added to the capacity of each buffer to avoid extra allocation on overflow.

smira commented 6 years ago

This is first step towards #2, as with tags it's next to impossible to estimate tags size before formatting them.