Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config parameters for setting TCP and UDP socket buffer sizes #54

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ This plugin supports the following configuration options plus the <<plugins-{typ
| <<plugins-{type}s-{plugin}-host>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-locale>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-port>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-tcp_receive_buffer_bytes>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-udp_receive_buffer_bytes>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-proxy_protocol>> |<<boolean,boolean>>|No
| <<plugins-{type}s-{plugin}-severity_labels>> |<<array,array>>|No
| <<plugins-{type}s-{plugin}-syslog_field>> |<<string,string>>|No
Expand Down Expand Up @@ -129,6 +131,31 @@ The port to listen on. Remember that ports less than 1024 (privileged
ports) may require root to use.

[id="plugins-{type}s-{plugin}-proxy_protocol"]

===== `tcp_receive_buffer_bytes`

* Value type is <<number,number>>
* There is no default value for this setting

The TCP socket receive buffer size in bytes.
If option is not set, the operating system default is used.
The operating system will use the max allowed value if `tcp_receive_buffer_bytes` is larger than allowed.
Consult your operating system documentation if you need to increase this max allowed value.

[id="plugins-{type}s-{plugin}-tcp_receive_buffer_bytes"]

===== `udp_receive_buffer_bytes`

* Value type is <<number,number>>
* There is no default value for this setting

The UDP socket receive buffer size in bytes.
If option is not set, the operating system default is used.
The operating system will use the max allowed value if `udp_receive_buffer_bytes` is larger than allowed.
Consult your operating system documentation if you need to increase this max allowed value.

[id="plugins-{type}s-{plugin}-udp_receive_buffer_bytes"]

===== `proxy_protocol`

* Value type is <<boolean,boolean>>
Expand Down
28 changes: 27 additions & 1 deletion lib/logstash/inputs/syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ class LogStash::Inputs::Syslog < LogStash::Inputs::Base
#
config :locale, :validate => :string

# The UDP socket receive buffer size in bytes.
# If option is not set, the operating system default is used.
# The operating system will use the max allowed value if receive_buffer_bytes is larger than allowed.
# Consult your operating system documentation if you need to increase this max allowed value.
config :udp_receive_buffer_bytes, :validate => :number

# The TCP socket receive buffer size in bytes.
# If option is not set, the operating system default is used.
# The operating system will use the max allowed value if receive_buffer_bytes is larger than allowed.
# Consult your operating system documentation if you need to increase this max allowed value.
config :tcp_receive_buffer_bytes, :validate => :number

public
def register
@metric_errors = metric.namespace(:errors)
Expand Down Expand Up @@ -140,6 +152,13 @@ def udp_listener(output_queue)
@udp.close if @udp
@udp = UDPSocket.new(Socket::AF_INET)
@udp.do_not_reverse_lookup = true
if @udp_receive_buffer_bytes
@udp.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, @udp_receive_buffer_bytes)
rcvbuf = @udp.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF).unpack("i")[0]
if rcvbuf != @udp_receive_buffer_bytes
@logger.warn("Unable to set udp_receive_buffer_bytes to desired size. Requested #{@udp_receive_buffer_bytes} but obtained #{rcvbuf} bytes.")
end
end
@udp.bind(@host, @port)

while !stop?
Expand All @@ -163,6 +182,13 @@ def tcp_listener(output_queue)

while !stop?
socket = @tcp.accept
if @tcp_receive_buffer_bytes
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, @tcp_receive_buffer_bytes)
rcvbuf = socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF).unpack("i")[0]
if rcvbuf != @tcp_receive_buffer_bytes
@logger.warn("Unable to set tcp_receive_buffer_bytes to desired size. Requested #{@tcp_receive_buffer_bytes} but obtained #{rcvbuf} bytes.")
end
end
@tcp_sockets << socket
metric.increment(:connections)

Expand All @@ -174,7 +200,7 @@ def tcp_listener(output_queue)
close_tcp
end # def tcp_listener

# tcp_receiver is executed in a thread, any uncatched exception will be bubbled up to the
# tcp_receiver is executed in a thread, any uncaught exception will be bubbled up to the
# tcp server thread and all tcp connections will be closed and the listener restarted.
def tcp_receiver(output_queue, socket)
ip, port = socket.peeraddr[3], socket.peeraddr[1]
Expand Down