<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
Hello,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
so-reuseport(1) is a good way of scaling UDP sources.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
In that case, datagrams are distributed to the appropriate UDP source using a hash based on (peer IP address, port) and (local IP address, port).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
This is the default balancing method of the SO_REUSEPORT kernel feature. Due to the hash implementation, there is also a high possibility of hashing collision, which results in uneven distribution of datagrams among sources.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
If that's a problem, custom BPF programs can be written that can use a different balancing method. AFAIK, this is not an option on RHEL 7 because of the old kernel version.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
(We have such a feature called udp-balancer(), but it is not available in the open-source edition:
<a href="https://support.oneidentity.com/technical-documents/syslog-ng-premium-edition/7.0.19/administration-guide/33#TOPIC-1387384" id="LPNoLP424189">
https://support.oneidentity.com/technical-documents/syslog-ng-premium-edition/7.0.19/administration-guide/33#TOPIC-1387384</a>)</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
Other than that, the following syslog-ng options can affect performance:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<ul>
<li>so-rcvbuf()/so-sndbuf(): Sets the maximum socket receive/send buffer in the kernel. The Linux kernel doubles this value (to allow space for bookkeeping). If syslog-ng stops processing new messages because, for example, the flags(flow-control) flag is set
 and destinations are slow, or just because it can't read datagrams fast enough; then kernel buffers will be filled and new datagrams will be dropped by the kernel.</li><li>log-iw-size(): The size of the initial source window. This value is used during flow control to stop reading new messages when more than log-iw-size() number of message is kept in memory.</li><li><b>log-fetch-limit()</b>: The maximum number of messages fetched from a source during a single poll loop. This is a performance-only option, the default is 10. You might want to increase this (to 100 for example) and test your performance. Please set this
 option together with log-iw-size():  log-iw-size() >= log-fetch-limit()<br>
</li><li>flags(flow-control): This is a log path option that enables flow-controlled message processing. You should probably NOT use this for UDP logs, details are below.</li></ul>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
UDP sources are non-blocking/event-based in syslog-ng, but they act like single-threaded entities, so you can consider a so-reuseport(1) source instance as an object that is bound to a single CPU core.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
This is why an <span lang="en"><span title="">even datagram distribution would be important to achieve the best "speed".</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<span lang="en"><span title=""> <br>
</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<span lang="en"><span title="">Enabling flags(flow-control)</span></span> on log paths containing your UDP sources probably won't help you avoid message loss, because it only makes sure that syslog-ng itself will not drop messages, but when you have log-iw-size()
 number of messages queued in syslog-ng, UDP sources will stop reading new messages. Due to this, kernel buffers will be filled, so datagrams will eventually be dropped by the kernel instead of syslog-ng.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
When flow-control is NOT configured in any of the log paths that contain your UDP sources, syslog-ng reads datagrams
<b>as fast as possible</b> (note the "single CPU core per source" limitation).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
In this case, syslog-ng will drop new messages when our destination queues are filled, for example when destinations are slow or connections are lost. The destination queue size can be set with the log-fifo-size() option. You can monitor dropped messages using
 the 'syslog-ng-ctl stats' command.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
--</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);">
László Várady<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> syslog-ng <syslog-ng-bounces@lists.balabit.hu> on behalf of brian hoffman <brianhoffman@yahoo.com><br>
<b>Sent:</b> Thursday, May 7, 2020 17:21<br>
<b>To:</b> syslog-ng@lists.balabit.hu <syslog-ng@lists.balabit.hu><br>
<b>Subject:</b> [syslog-ng] UDP drops with syslog-ng 3.24.1-1</font>
<div> </div>
</div>
<div>
<div style="background-color:#FFEB9C; width:100%; border-style:solid; border-color:#9C6500; border-width:1pt; padding:2pt; font-size:10pt; line-height:12pt; font-family:'Calibri'; color:Black; text-align:left">
<span style="color:#9C6500; font-weight:bold">CAUTION:</span> This email originated from outside of the organization. Do not follow guidance, click links, or open attachments unless you recognize the sender and know the content is safe.</div>
<br>
<div>
<div class="x_ydp791e652fyahoo-style-wrap" style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
<div dir="ltr">
<div>
<div dir="ltr">We've been centrally logging with syslog-ng for about 5 years now.  Over that time, the number of sources has grown significantly, and at some point we crossed a line where drops were happening (a quick survey of 3 million syslog packets yielded
 420 unique currently sending hosts).  After much research and experimentation, we've been able to get to the point where throughout the day there are 0 drops for the most part.  This was achieved by installing the latest syslog-ng (not the RedHat packaged
 one) and creating a source for each CPU.  Occasionally, though, we still have periods of drops so I'm trying to eliminate these last few.</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Here are some relevant configuration items:</div>
<div dir="ltr">2 RedHat 7.8 VMs (load balanced via an F5) with 16GB memory and 4 CPUs each running <span><span style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">syslog-ng-3.24.1-1.el7.x86_64.</span></span></div>
<div dir="ltr">
<div>
<div>net.core.rmem_default = 212992</div>
<div>net.core.rmem_max = 268435456</div>
</div>
<div dir="ltr"><br>
</div>
<span>log_fifo_size(268435456);</span><br>
</div>
<div dir="ltr"><span><br>
</span></div>
<div dir="ltr">
<div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
source s_network {</div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
network(ip("0.0.0.0") port(514) transport("udp") so_rcvbuf(441326592) so-reuseport(1) persist-name("udp1"));</div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
network(ip("0.0.0.0") port(514) transport("udp") so_rcvbuf(441326592) so-reuseport(1) persist-name("udp2"));</div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
network(ip("0.0.0.0") port(514) transport("udp") so_rcvbuf(441326592) so-reuseport(1) persist-name("udp3"));</div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
network(ip("0.0.0.0") port(514) transport("udp") so_rcvbuf(441326592) so-reuseport(1) persist-name("udp4"));</div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
network(ip("0.0.0.0") port(514) transport("tcp") max_connections(200) keep_alive(yes) so_rcvbuf(67108864));</div>
<div style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">
};</div>
</div>
</div>
<div dir="ltr"><span><br>
</span></div>
<div dir="ltr"><span>We are limited to UDP, unfortunately, because we do not have control over the devices/networks/etc. that are sending to us, but we have changed as many of the internal senders and destinations to TCP as we can.</span></div>
<div dir="ltr"><span><br>
</span></div>
<div dir="ltr">With a script I created to view the packets, including drops, as well as the individual RECVQs, the issue can be illustrated.</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Here's what things look like normally:</div>
<div dir="ltr">
<div>
<div>Thu May  7 10:48:15 EDT 2020, 27003 IP pkts rcvd,26980 IP pkts sent,24951 UDP pkts rcvd, 28075 UDP pkts sent,0 UDP pkt rcv err<br>
</div>
<div>RECVQ-1=2176</div>
<div>RECVQ-2=0</div>
<div>RECVQ-3=0</div>
<div>RECVQ-4=0</div>
<div>Thu May  7 10:48:16 EDT 2020, 28453 IP pkts rcvd,28426 IP pkts sent,26185 UDP pkts rcvd, 29180 UDP pkts sent,0 UDP pkt rcv err</div>
<div>RECVQ-1=0</div>
<div>RECVQ-2=0</div>
<div>RECVQ-3=4352</div>
<div>RECVQ-4=0</div>
<div>Thu May  7 10:48:17 EDT 2020, 28294 IP pkts rcvd,28276 IP pkts sent,26277 UDP pkts rcvd, 28709 UDP pkts sent,0 UDP pkt rcv err</div>
<div>RECVQ-1=2176</div>
<div>RECVQ-2=0</div>
<div>RECVQ-3=0</div>
<div>RECVQ-4=0</div>
<div><br>
</div>
</div>
The RECVQs are sparsely used, and there are no errors.</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Around 9pm every night, the packet counts go up significantly (probably due to backup related logs):</div>
<div>Wed May  6 21:00:08 EDT 2020, 66382 IP pkts rcvd,66366 IP pkts sent,39405 UDP pkts rcvd, 67592 UDP pkts sent,0 UDP pkt rcv err</div>
<div>RECVQ-1=1595008</div>
<div>RECVQ-2=106217088</div>
<div>RECVQ-3=53694976</div>
<div>RECVQ-4=31858816</div>
<div>Wed May  6 21:00:09 EDT 2020, 69317 IP pkts rcvd,69338 IP pkts sent,44446 UDP pkts rcvd, 75958 UDP pkts sent,0 UDP pkt rcv err</div>
<div>RECVQ-1=13056</div>
<div>RECVQ-2=126397312</div>
<div>RECVQ-3=75568128</div>
<div>RECVQ-4=41626880</div>
<div>Wed May  6 21:00:10 EDT 2020, 71205 IP pkts rcvd,71227 IP pkts sent,43657 UDP pkts rcvd, 74603 UDP pkts sent,0 UDP pkt rcv err</div>
<div>RECVQ-1=920448</div>
<div>RECVQ-2=146122752</div>
<div>RECVQ-3=100951168</div>
<div>RECVQ-4=52622208</div>
<div>Wed May  6 21:00:12 EDT 2020, 69578 IP pkts rcvd,69454 IP pkts sent,124465 UDP pkts rcvd, 163367 UDP pkts sent,0 UDP pkt rcv err</div>
<div>RECVQ-1=13140864</div>
<div>RECVQ-2=44494848</div>
<div>RECVQ-3=125579136</div>
<div>RECVQ-4=0</div>
<div><br>
</div>
</div>
<div dir="ltr">Still, though, it's handling it with no errors.  But then at some point a threshold is reached and errors start piling up:</div>
<div>
<div>Wed May  6 21:00:20 EDT 2020, 63177 IP pkts rcvd,63291 IP pkts sent,0 UDP pkts rcvd, 0 UDP pkts sent,38011 UDP pkt rcv err</div>
<div>RECVQ-1=536871424</div>
<div>RECVQ-2=200357376</div>
<div>RECVQ-3=292948352</div>
<div>RECVQ-4=28890752</div>
<div>Wed May  6 21:00:21 EDT 2020, 69501 IP pkts rcvd,69464 IP pkts sent,0 UDP pkts rcvd, 1 UDP pkts sent,42158 UDP pkt rcv err</div>
<div>RECVQ-1=536871424</div>
<div>RECVQ-2=223551360</div>
<div>RECVQ-3=314995584</div>
<div>RECVQ-4=41735680</div>
<div>Wed May  6 21:00:23 EDT 2020, 69962 IP pkts rcvd,69978 IP pkts sent,0 UDP pkts rcvd, 2 UDP pkts sent,43775 UDP pkt rcv err</div>
<div>RECVQ-1=536871424</div>
<div>RECVQ-2=244732544</div>
<div>RECVQ-3=338239616</div>
<div>RECVQ-4=53858176</div>
<div>Wed May  6 21:00:24 EDT 2020, 68266 IP pkts rcvd,68216 IP pkts sent,0 UDP pkts rcvd, 0 UDP pkts sent,43118 UDP pkt rcv err</div>
<div>RECVQ-1=536871424</div>
<div>RECVQ-2=265258752</div>
<div>RECVQ-3=360643712</div>
<div>RECVQ-4=65362688</div>
<div><br>
</div>
</div>
The common denominator I've found is that one of the RECVQs hits <span><span style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">536,871,424.  This number seems to be almost exactly double (512 difference) the rmem.max/log_fifo_size
 (<span><span style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px">268,435,456).  Even though there seems to be capacity in the other RECVQs, just one of those hitting that magic number seems to be enough to throw
 things out of whack.  During this time, the CPU usage for syslog-ng also drops:</span></span></span></span></div>
<div dir="ltr"><span><span style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px"><span><span style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px"><br>
</span></span></span></span></div>
<div dir="ltr"><span><span style="color:rgb(0,0,0); font-family:Helvetica Neue,Helvetica,Arial,sans-serif; font-size:16px"><span>
<div>
<div>top - 21:00:11 up 2 days,  8:40,  2 users,  load average: 1.09, 1.41, 1.32</div>
<div>   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND</div>
<div>  7214 root      20   0 2111388   1.7g   5392 S 123.6 10.9   3080:46 syslog-ng</div>
<div> </div>
<div>top - 21:00:14 up 2 days,  8:40,  2 users,  load average: 1.00, 1.39, 1.31</div>
<div>   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND</div>
<div>  7214 root      20   0 2111388   1.7g   5392 S  24.6 10.9   3080:46 syslog-ng</div>
<div> </div>
<div>top - 21:00:17 up 2 days,  8:40,  2 users,  load average: 1.00, 1.39, 1.31</div>
<div>   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND</div>
<div>  7214 root      20   0 2111388   1.7g   5392 S   7.6 10.9   3080:47 syslog-ng</div>
</div>
</span></span></span></div>
<div><br>
</div>
<div dir="ltr">As best I can tell, based on the reading I've done, the message counts we're getting should be doable, but it's still not clear exactly how to size some of these options as they relate to UDP (like log_fetch_limit, which we do not have set).</div>
<div dir="ltr">
<div><br>
</div>
<div dir="ltr">Anything else I should try?</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>