fluentd
fluentd copied to clipboard
out_http: Add option to reuse connections
Which issue(s) this PR fixes: N/A
What this PR does / why we need it: The HTTP output plugin recreates a connection for every HTTP request. In combination with TLS and high network latencies, this can result in very poor performance. This PR adds an option to reuse connections.
The implementation caches one connection per flush thread. The cache is part of the HTTP plugin instance and is implemented as an array. When a thread creates its first request, it gets assigned a slot (id) in this array and the id is stored in a thread local variable. Since this slot is exclusively used by a single thread, no synchronization is required. If the endpoint changes at runtime, the old connection will be closed and replaced by a new connection to the new endpoint. During shutdown, all open connections are finished in the close
method.
This implementation works very well for a static endpoint. If the endpoint changes frequently, there will be little benefit. However, it can be assumed that most users use a static endpoint.
Benchmark I tested the throughput with two Fluentd instances on a single machine. One instance acting as sender and the other as receiver. Even though the connection creation was very fast, because both instances were located on the same machine and TLS was not enabled, activating connection reuse doubled the throughput.
Sender configuration:
<source>
@type sample
sample {"hello":"world"}
tag sample
rate 5000
</source>
<match **>
@type http
endpoint http://localhost:9000
open_timeout 2
reuse_connections true
<format>
@type json
</format>
<buffer>
flush_interval 10s
chunk_limit_records 1
flush_thread_count 32
</buffer>
</match>
Receiver configuration:
<system>
workers 1
</system>
<source>
@type http
port 9000
bind 0.0.0.0
body_size_limit 32m
keepalive_timeout 10s
</source>
<match **>
@type flowcounter_simple
unit second
</match>
Docs Changes:
Release Note: out_http: Add option to reuse connections