You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are trying to switch our compression algorithm from snappy to zstd, we are seeing about 25% more compressed bytes which is good but we are also seeing more CPU usage which is bad. We ended up adding 60% more pods to handle the same traffic load.
We are using sarama v1.14.0 and klauspost v1.71.4.
We generated a few stack traces and found about 75 go routines are stuck waiting for malloc, I haven't find a zstd go routine doing any real work except waiting for the malloc.
After discussion with clauspost/compress community, the recommendation is to pass a pre-allocated dst buffer instead of nil (2nd argument in the below code segment):
If sarama community thinks this is the right way to fix this problem to make zstd compression performant, I can submit a PR to add the following config option for zstd compression path:
In zstd.go, each ZstdEncoder can have pre-allocated slice dstBuffer of DesintationBufferSize if this param is set. When function zstdCompress() is invoked and when dst argument is nil and len(src) is less than DestinationBufferSize, we will use this pre-allocated dstBuffer slice to call the underlying zstd library.
Description
zstd compression wastes too much time on malloc due to lack of destination buffer
Versions
Sarama v1.41.0
Configuration
Logs
logs: malloc
Additional Context
We are trying to switch our compression algorithm from snappy to zstd, we are seeing about 25% more compressed bytes which is good but we are also seeing more CPU usage which is bad. We ended up adding 60% more pods to handle the same traffic load.
We are using sarama v1.14.0 and klauspost v1.71.4.
We generated a few stack traces and found about 75 go routines are stuck waiting for malloc, I haven't find a zstd go routine doing any real work except waiting for the malloc.
I think the malloc is from this line:
https://github.com/klauspost/compress/blob/v1.17.4/zstd/encoder.go#L516
// If less than 1MB, allocate a buffer up front.
if len(dst) == 0 && cap(dst) == 0 && len(src) < 1<<20 && !e.o.lowMem {
dst = make([]byte, 0, len(src))
}
Related issue is also fired on zstd compression library:
klauspost/compress#987
After discussion with clauspost/compress community, the recommendation is to pass a pre-allocated dst buffer instead of nil (2nd argument in the below code segment):
https://github.com/IBM/sarama/blob/main/compress.go#L190
case CompressionZSTD:
return zstdCompress(ZstdEncoderParams{level}, nil, data)
The text was updated successfully, but these errors were encountered: