Skip to content

perf: obs-outputs: batch RTMP chunks into one writev/sendmsg #3207

Closed

Description

@zackees

What

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.

Activity

  1. added
    enhancement
    P3
    size:M
    on Oct 31, 2026
  2. zackees commented on Oct 31, 2026

    @zackees
    MemberAuthor

    /ready

  3. added
    ready
    on Oct 31, 2026
  4. zackees commented on Nov 1, 2026

    @zackees
    MemberAuthor

    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:

    1. 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).
    2. 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.
    3. Platform: the batched send is POSIX host code, so it goes in a host file per the Rename platform folders and files to hosts/{windows,macos,linux,posix} (match the Rust layout) #1009 rule, not behind a new #ifdef in rtmp.c. Windows keeps the current path for now (WSASend is a follow-up).
    4. 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.

    First PR next tick.

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

Metadata

Metadata

Assignees

Labels

P3enhancementreadysize:M

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions