You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: obs-outputs: batch RTMP chunks into one writev/sendmsg #3207
plugins/obs-outputs/librtmp/rtmp.c:4258-4275 calls send() once per 4096-byte chunk (rtmp-stream.c.h:991) with TCP_NODELAY (rtmp.c:926): about 37 syscalls per 150 KB keyframe.
Proposed change
Build an iovec over the in-place type-3 headers and send once (MSG_NOSIGNAL); batch into one buffer for TLS. A cheaper partial step is a larger out chunk size.
Acceptance criteria
Before/after numbers (strace -c on a loopback RTMP sink at 6 and 50 Mbps) in the PR; nothing lands unmeasured.
RED then GREEN; Tier 3 parity stays bit-exact unless this issue says otherwise.
Found by a read-only code scout and not yet measured. Parent: #3176.
Claiming: perf: obs-outputs batch RTMP chunks into one writev/sendmsg
Checked first: new_socket_loop is off by default (rtmp-stream.c.h:1265), so RTMP_SendPacket calls WriteN → RTMPSockBuf_Send once per chunk: about 37 send() calls for a 150 KB keyframe at the 4096-byte out chunk size. One correction to the description: OBS sets m_bUseNagle = true, so TCP_NODELAY is off. The kernel already coalesces the segments, and the cost is the syscalls, not packets on the wire.
Plan, one PR:
RED: a new cmocka test builds librtmp, points an RTMP at a socketpair, and sends a 150 KB video packet with RTMP_SendPacket. It checks that the bytes on the peer equal the current chunked stream byte for byte (captured from the unchanged code), and that the socket sees at most 2 send calls (counted with --wrap).
GREEN: for a plain TCP socket (no HTTP tunnel, no custom send, no TLS), build an iovec of [chunk header, chunk data] pairs and send it with sendmsg(MSG_NOSIGNAL), looping on partial writes and capping at IOV_MAX. Headers go in a separate small array: the in-place type-3 header trick overwrites the previous chunk's tail, which only works one chunk at a time. TLS, HTTP and the custom-send loop keep the current per-chunk path.
Numbers: strace -c -e trace=sendto,sendmsg on a loopback socketpair sink for a 6 and a 50 Mbps packet mix, from the test harness, since a real ingest isn't available here.
Activity
zackees commentedon Oct 31, 2026
/ready
zackees commentedon Nov 1, 2026
Claiming: perf: obs-outputs batch RTMP chunks into one writev/sendmsg
Checked first:
new_socket_loopis off by default (rtmp-stream.c.h:1265), soRTMP_SendPacketcallsWriteN→RTMPSockBuf_Sendonce per chunk: about 37send()calls for a 150 KB keyframe at the 4096-byte out chunk size. One correction to the description: OBS setsm_bUseNagle = true, so TCP_NODELAY is off. The kernel already coalesces the segments, and the cost is the syscalls, not packets on the wire.Plan, one PR:
RTMPat a socketpair, and sends a 150 KB video packet withRTMP_SendPacket. It checks that the bytes on the peer equal the current chunked stream byte for byte (captured from the unchanged code), and that the socket sees at most 2 send calls (counted with--wrap).sendmsg(MSG_NOSIGNAL), looping on partial writes and capping at IOV_MAX. Headers go in a separate small array: the in-place type-3 header trick overwrites the previous chunk's tail, which only works one chunk at a time. TLS, HTTP and the custom-send loop keep the current per-chunk path.#ifdefinrtmp.c. Windows keeps the current path for now (WSASend is a follow-up).strace -c -e trace=sendto,sendmsgon a loopback socketpair sink for a 6 and a 50 Mbps packet mix, from the test harness, since a real ingest isn't available here.First PR next tick.
perf(obs-outputs): write an RTMP message to the socket in one call (o…