Skip to content

rsyslog: stop omuxsock reopening its socket for every message - #20637

Open
Muhammad Falak R Wani (mfrw) wants to merge 1 commit into
3.0-devfrom
mfrw/rsyslog-3.0-omuxsock-reopen
Open

Muhammad Falak R Wani (mfrw) wants to merge 1 commit into
3.0-devfrom
mfrw/rsyslog-3.0-omuxsock-reopen

Conversation

@mfrw

@mfrw Muhammad Falak R Wani (mfrw) commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

omuxsock calls doTryResume() before every message, and doTryResume()
closes the socket and opens a new one each time. So each forwarded
message costs close() + socket() + sendto() instead of a single
sendto(). At tens of thousands of messages per second, that is a
large share of rsyslog's CPU.

Backport item (d) of upstream PR rsyslog/rsyslog#5630, released in
8.2512.0: only open the socket when none is open. The socket is an
unconnected SOCK_DGRAM socket, and each sendto() names the destination,
so delivery and error handling do not change. The rest of that PR adds
new omuxsock features, which are not needed for this fix, and neither
are its follow-ups.

Tested 8.2308.0-9 on Azure Linux 3.0 (imuxsock -> omuxsock):

  • 5000 messages took 5000 sendto() calls and no socket() or close()
    calls. With 8.2308.0-7 they took 5000 socket(), 5001 close() and
    5000 sendto().
  • rsyslogd used about 0.5 s of CPU per 200000 messages, down from
    about 1.5 s.
  • No messages were lost, and a sink restarted at the same path keeps
    receiving.
  • Upstream uxsock_simple.sh passes with and without the patch.

BuddyBuild: link
Fixes: https://mariner-org.visualstudio.com/mariner/_workitems/edit/25606

Signed-off-by: Muhammad Falak R Wani falakreyaz@gmail.com

@mfrw
Muhammad Falak R Wani (mfrw) requested a review from a team as a code owner December 2, 2026 06:27
@microsoft-github-policy-service microsoft-github-policy-service Bot added Packaging 3.0-dev PRs Destined for AzureLinux 3.0 labels Dec 2, 2026
@mfrw

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

omuxsock calls doTryResume() before every message, and doTryResume()
closes the socket and opens a new one each time. So each forwarded
message costs close() + socket() + sendto() instead of a single
sendto(). At tens of thousands of messages per second, that is a
large share of rsyslog's CPU.

Backport item (d) of upstream PR rsyslog/rsyslog#5630, released in
8.2512.0: only open the socket when none is open. The socket is an
unconnected SOCK_DGRAM socket, and each sendto() names the destination,
so delivery and error handling do not change. The rest of that PR adds
new omuxsock features, which are not needed for this fix, and neither
are its follow-ups.

Tested 8.2308.0-9 against the same spec without the patch
(8.2308.0-8), both built with the same toolchain, in Azure Linux 3.0
containers (imuxsock -> omuxsock -> Unix datagram receiver):
- Socket syscalls per forwarded message drop from 3 to 1.
- rsyslogd CPU is 10-23% lower at 10,000-100,000 msg/s. Maximum
  throughput rises from 161,775 to 300,843 msg/s, with 42% less CPU
  per message.
- No messages were lost or duplicated across 144 million messages,
  including a 60-minute soak. A receiver that restarts, stalls or is
  missing, repeated SIGHUP and an rsyslog restart all behave as before.
- Upstream uxsock_simple.sh and the imuxsock tests give the same
  results with and without the patch.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
@mfrw

Copy link
Copy Markdown
Member Author

rsyslog omuxsock: stop reopening the socket for every message (Azure Linux 3.0) — stress test report

Change: rsyslog 8.2308.0-9 for Azure Linux 3.0 (3.0-dev) adds one patch: a backport of item (d) of upstream rsyslog PR 5630, commit ff3ec4c31dc3. It tracks Bug 25606.

Summary

  • Problem. The omuxsock output in rsyslog 8.2308.0 closes its Unix socket and opens a new one before every message it forwards. Each message therefore costs close() + socket() + sendto() instead of a single sendto(). The requesting team reported that this costs about 10% system CPU at their log rates, and that rsyslog hit 100% CPU in customer incidents.
  • Fix. Open the socket once and keep using it; open a new one only if none is open. Upstream rsyslog has used this code since 8.2512.0 (December 2025), and Azure Linux 4.0's rsyslog 8.2604.0 already ships it. The code change is about six lines in one function.
  • Results. Both builds come from the same spec and toolchain, and differ only by this patch:
    • Socket syscalls per forwarded message drop from 3 to 1.
    • rsyslogd CPU is 10–23% lower at every tested rate from 10,000 to 100,000 msg/s. For example, at 25,000 msg/s it drops from 57% to 44% of one core.
    • Maximum throughput rises from 161,775 to 300,843 msg/s (+86%), and CPU per message falls by 42%.
      • Under that load the unpatched build fills its 100,000-message queue. The patched build keeps up.
    • p99 latency at fixed rates falls by 30–50%, for example from 121 to 62 µs at 50,000 msg/s.
    • No message was lost or duplicated in any run that should not lose messages. That is 144,220,000 messages per build, including the soak.
    • Failure behaviour is unchanged. Both builds react identically to:
      • a receiver that restarts or stalls;
      • a receiver that is missing;
      • repeated SIGHUP;
      • an rsyslog restart.
    • 60-minute soak at 30,000 msg/s: 108,000,000 messages per build, none lost. Memory stayed flat at about 4.4 MB RSS from start to end. The patched build held a constant 8 open files, while the baseline moved between 7 and 8 as it closed and reopened its socket. Patched used 58.7% of a core against 66.8% for the baseline.
    • Regression:
      • Upstream rsyslog tests give identical results with and without the patch.
      • Only omuxsock.so code changes: 57 of the 58 packaged files are identical, and RPM dependencies and file lists are unchanged.
      • Upgrading from today's 8.2308.0-7 and rolling back both work.
      • The x86_64 build passes the same functional checks.
  • Risk: low. The socket being kept open is connectionless (datagram), and every sendto() names the destination path. So a restarted or replaced receiver is reached exactly as before, and errors are handled exactly as before.
  • Recommendation: take this into 3.0-dev for the next azlstable release.

The change

 static rsRetVal doTryResume(instanceData *pData)
 {
 	DEFiRet;
 
-	DBGPRINTF("omuxsock trying to resume\n");
-	closeSocket(pData);
-	iRet = openSocket(pData);
+	if(pData->sock == INVLD_SOCK) {
+		DBGPRINTF("omuxsock trying to resume\n");
+		iRet = openSocket(pData);
 
-	if(iRet != RS_RET_OK) {
-		iRet = RS_RET_SUSPENDED;
+		if(iRet != RS_RET_OK) {
+			iRet = RS_RET_SUSPENDED;
+		}
 	}
 
 	RETiRet;
 }

doAction() calls doTryResume() before every message, so in the old code every message closed the socket and opened a new one.

The rest of PR 5630 adds new features: abstract socket names, network namespaces and connected socket types. It builds on PR 6121, which adds the network namespace APIs, and PR 6750 later fixed message loss in those new connected modes. None of that is needed for this fix, and none of it is included. azurelinux PR 18262 backports all three; this change takes only the fix the requesting team asked for.

How it was tested

  • Builds.
    • Baseline: rsyslog-8.2308.0-8.azl3, today's 3.0-dev.
    • Patched: rsyslog-8.2308.0-9.azl3, which adds this patch.
    • Both were built from the same spec, with the same toolchain, in Azure Linux 3.0 containers.
  • Pipeline: load generator → /dev/log (imuxsock) → rsyslog main queue → omuxsock → Unix datagram receiver.
    • rsyslog runs with its default queue settings and with imuxsock rate limiting off.
    • net.unix.max_dgram_qlen is 10, the Azure Linux 3.0 default.
  • Tools.
    • A C load generator with exact pacing, which stamps every message with a sequence number and a send time.
    • A C receiver that counts lost, duplicated and reordered messages and records end-to-end latency.
    • rsyslogd CPU, memory, open files and context switches read from /proc.
    • rsyslog impstats for queue and action counters, and strace for syscall counts.
  • Method. Baseline and patched runs alternate scenario by scenario, so both see the same conditions. The rate sweep and the max-throughput test are repeated 3 times; tables show the mean, and ± one standard deviation where given.
  • Hardware. An 8-vCPU aarch64 VM running Fedora kernel 7.3, using Azure Linux 3.0 container userspace. The x86_64 build was checked functionally under emulation.

Results

Syscalls per forwarded message (strace -f -c, 20,000 messages)

syscall baseline patched
socket 1.00 0.00
close 1.00 0.00
connect 0.00 0.00
sendto 1.00 1.00
socket-related total 3.00 1.00

Socket churn (20,000 msg/s for 10 s, /proc sampled every 200 ms)

baseline patched
distinct socket inodes seen in rsyslogd 51 3
open fds (max) 8 8

CPU and latency at fixed message rates (200-byte messages, 30 s per run, 3 runs each)

rate (msg/s) delivered rsyslogd CPU baseline → patched (% of one core) CPU per message (µs) p99 latency (µs)
10,000 1,800,000/1,800,000 22.9 ± 0.6 → 18.0 ± 0.1 (-21%) 22.86 → 18.02 129 → 64
25,000 4,500,000/4,500,000 57.3 ± 0.8 → 44.4 ± 0.1 (-23%) 22.90 → 17.75 112 → 65
50,000 9,000,000/9,000,000 73.0 ± 0.8 → 57.7 ± 0.2 (-21%) 14.59 → 11.54 121 → 62
75,000 13,500,000/13,500,000 81.9 ± 0.5 → 73.3 ± 0.3 (-10%) 10.92 → 9.78 129 → 70
100,000 18,000,000/18,000,000 95.4 ± 2.4 → 77.8 ± 0.2 (-18%) 9.54 → 7.78 114 → 79

Maximum throughput (2,000,000 messages from 2 unpaced senders, 3 runs)

baseline patched change
end-to-end throughput (msg/s) 161,775 ± 1,251 300,843 ± 3,316 +86%
rsyslogd CPU per message (µs) 9.18 5.29 -42%
rsyslogd CPU (% of one core) 148.5 159.1
messages lost 0 0
main queue backlog (max messages) 100,000 847
p99 latency (µs) 670,104 151

Total CPU is slightly higher with the patch here only because it moves 86% more messages per second; per message it uses 42% less. The baseline's p99 latency is high because its queue stays full.

Message size sweep (25,000 msg/s, 20 s, 2 runs)

message bytes delivered CPU baseline → patched (% of one core) CPU per message (µs)
64 2,000,000/2,000,000 54.3 → 44.1 (-19%) 21.75 → 17.66
512 2,000,000/2,000,000 55.3 → 44.7 (-19%) 22.14 → 17.88
2,048 2,000,000/2,000,000 58.8 → 47.5 (-19%) 23.50 → 18.98
8,000 2,000,000/2,000,000 67.2 → 56.8 (-16%) 26.91 → 22.73

Concurrency and multiple outputs

scenario lost (baseline / patched) CPU % baseline → patched distinct sockets (b / p) max fds (b / p)
4 action-queue workers, 4 senders, 50,000 msg/s total, 20 s 0 / 0 73.7 → 62.3 not sampled / not sampled 8 / 8
2 omuxsock actions to 2 sinks, 20,000 msg/s, 20 s 0 / 0 56.2 → 44.0 189 / 4 9 / 9

Fault injection (20,000 msg/s)

scenario baseline patched
Sink killed under load, path gone ~2 s, new sink bound lost 40,006 of 600,000; expected ≈40,194; first msg after re-bind < 10 ms lost 40,010 of 600,000; expected ≈40,200; first msg after re-bind < 10 ms
Sink frozen (SIGSTOP) for 4 s under load lost 0 of 400,000; 2,212 delivered out of order lost 0 of 400,000; 2,382 delivered out of order
Sink absent for the first 5 s lost 99,998 of 400,000; expected ≈100,000; first msg after sink up < 10 ms lost 100,055 of 400,000; expected ≈100,000; first msg after sink up < 10 ms
SIGHUP to rsyslogd every second for 19 s lost 0 of 400,000; 93 sockets seen lost 0 of 400,000; 3 sockets seen
rsyslogd stopped and restarted under load lost 3 of 400,000; delivers after restart lost 3 of 400,000; delivers after restart

Soak (60 minutes at 30,000 msg/s, both variants side by side)

baseline patched
messages sent 108,000,000 108,000,000
messages delivered 108,000,000 108,000,000
lost 0 0
duplicates 0 0
rsyslogd CPU (% of one core, whole run) 66.8 58.7
CPU per message (µs) 22.27 19.55
RSS KiB start → end 4,476 → 4,536 (max 6,740) 4,496 → 4,484 (max 5,080)
open fds (min–max) 7–8 8–8
p99 / max latency (µs) 350 / 158,960 367 / 38,684

The soak ran while other test jobs, the x86_64 emulated build and the upstream test build, were using the same VM. So its latency tail and absolute CPU figures are noisier than in the dedicated runs above. Both builds saw the same conditions.

Loss accounting across the 66 runs that should not lose messages: baseline delivered 144,220,000 of 144,220,000, patched delivered 144,220,000 of 144,220,000.

Regression, packaging and upgrade

  • Upstream rsyslog tests. I ran the omuxsock and imuxsock tests from the 8.2308.0 tree on both versions, and the results are identical:

    patched without the patch
    passed 8 8
    skipped 8 8
    failed 1 1

    The skipped tests are missing optional prerequisites. The one failure, imuxsock_logger_root.sh, fails the same way without the patch in this container environment. uxsock_simple.sh, the omuxsock test, passes on both.

  • Package contents.

    • Requires, Provides and file lists are identical for all four subpackages.
    • 57 of the 58 packaged files are identical. Binaries were compared on their code section, so build IDs and version stamps don't count.
    • The only file whose code differs is /usr/lib/rsyslog/omuxsock.so.
  • Upgrade and rollback.

    • Upgrading from the production 8.2308.0-7 package to 8.2308.0-9 works, and rsyslogd -N1 accepts the config.
    • tdnf downgrade back to 8.2308.0-7 also works.
    • Config files under /etc/rsyslog.d/ are kept.
  • x86_64. I built both versions for x86_64 and ran them under emulation, so CPU numbers are not meaningful there:

    • Both delivered 20,000 of 20,000 messages.
    • In the receiver-restart test both lost 4,028–4,029 messages, against about 4,038 expected while the receiver was down, and both kept delivering afterwards.
    • rsyslogd opened 53 sockets (baseline) versus 3 (patched) in 10 seconds.

Something we already ship today (not changed here)

  • The Azure Linux 3.0 spec doesn't mark /etc/rsyslog.conf as a %config file.
  • So every rsyslog update overwrites local edits to it, without saving a .rpmsave. I confirmed this with the current -7 → -8 security update.
  • Files in /etc/rsyslog.d/ are kept.
  • Anyone who configured omuxsock directly in /etc/rsyslog.conf should move that config to /etc/rsyslog.d/.
  • Marking the file %config(noreplace) should be a separate change.

@mfrw
Muhammad Falak R Wani (mfrw) force-pushed the mfrw/rsyslog-3.0-omuxsock-reopen branch from fd1d8e9 to fce2c14 Compare December 2, 2026 09:52

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0-dev PRs Destined for AzureLinux 3.0 Packaging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant