vector: Perfomance degradation in elasticsearch sink when using compression (gzip or zlib) after v0.34.0
A note for the community
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Problem
[Tl;DR] After vector version 0.33.1 (since 0.34.0), the elastic search sink performance is very poor when using compression option. (50% degraded of throughput and cpu & memory usage is very high)
Recently I upgraded vector from 0.27 to 0.36, then I can observe the performance degrade. So I do regression test to point out which version is the problem. I can find that after 0.34.0 the elasticsearch sink performance is very poor.
After observe the performance degrade, I do perf profiling v0.33.1 vs v0.34.0, then I can find difference between two version’s flame graph
[Version v0.33.1]
[Version v0.34.0]
After version v0.34.0, the memory set system call count is very high when to do GzEncoder (I also confirm that this call stack occur when I using the zlib compression rather than gzip)
After these debugging, I turn off the compression and then I can observe the performance is almost same with previous version.
But of course, the memory usage is high because the compression is disabled
I think this problem is related to https://github.com/vectordotdev/vector/pull/18850 and https://github.com/rust-lang/flate2-rs/issues/395
Thank you.
Configuration
[api]
enabled = true
address = "0.0.0.0:9600"
[log_schema]
host_key = "_vector_host"
metadata_key = "_vector_metadata"
source_type_key = "_vector_source"
message_key = "_vector_message"
timestamp_key = "_vector_timestamp"
[sources.kafka]
type = "kafka"
bootstrap_servers = "***"
topics = ["***"]
group_id = "***"
decoding.codec = "json"
auto_offset_reset = "latest"
fetch_wait_max_ms = 10000
session_timeout_ms = 10000
headers_key = "\"@metadata\".kafka.headers"
key_field = "\"@metadata\".kafka.key"
offset_key = "\"@metadata\".kafka.offset"
partition_key = "\"@metadata\".kafka.partition"
topic_key = "\"@metadata\".kafka.topic"
[sources.kafka.librdkafka_options]
"client.id" = "***"
"max.poll.interval.ms" = "300000"
"heartbeat.interval.ms" = "5000"
"fetch.min.bytes" = "102400"
"socket.receive.buffer.bytes" = "4096000"
[sinks.to_es]
type = "elasticsearch"
inputs = ["kafka"]
endpoint = "***"
encoding.except_fields = ["_vector_source", "_vector_timestamp", "@metadata"]
mode = "bulk"
bulk.action = "index"
bulk.index = "***"
id_key = "\"@metadata\".documentId"
bulk.max_bytes = 7680000
compression = "gzip"
request.timeout_secs = 7200
request.rate_limit_duration_secs = 1
request.rate_limit_num = 15
buffer.max_events = 5000
request_retry_partial = true
[sources.internal_metrics]
type = "internal_metrics"
scrape_interval_secs = 15
namespace = "vector"
[sinks.internal_metrics_to_prometheus]
inputs = ["internal_metrics"]
type = "prometheus_exporter"
address = "0.0.0.0:9601"
default_namespace = "default"
Version
v0.34.0
Debug Output
No response
Example Data
No response
Additional Context
No response
References
No response
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Reactions: 2
- Comments: 15 (10 by maintainers)
Commits related to this issue
- fix(compression): Fix gzip and zlib performance degradation Fix gzip and zlib performance degradation caused by: * flate2 v1.0.28 started to resize its input buffer up to its capacity and back to t... — committed to Hexta/vector by Hexta 4 months ago
- fix(compression): Fix gzip and zlib performance degradation Fix gzip and zlib performance degradation caused by: * flate2 v1.0.28 started to resize its input buffer up to its capacity and back to t... — committed to Hexta/vector by Hexta 4 months ago
- fix(compression): Fix gzip and zlib performance degradation Fix gzip and zlib performance degradation caused by: * flate2 v1.0.28 started to resize its input buffer up to its capacity and back to t... — committed to Hexta/vector by Hexta 4 months ago
@Byron This is just a draft version of the patch to verify the idea. It should be moved to Compressor.
I think the solution make sense though, as you suggest, it should be implemented in the Compressor so that all sinks can benefit.
Thanks for the hint! I think I put the pieces together now. The problem is that the internal buffer is created with 32kb capacity. However, with each small write it’s memset to its full capacity, just to be truncated to what’s actually written right after.
I will report this over at
flate2in the hopes that this is fixable, even though in a way the issue that it uncovered along with a fix that further improves performance compared to the previous version seems like a net-positive.Hey, Maybe, it’s worth adding a buffered writer for *Encoder writers? I’ve tried to use 10KB buffer and performance improved a lot, similar to v0.33.0.
Vector at revision b3889bcea
Vector at revision b3889bcea with buffered writer