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

liburing #1218

Merged
merged 53 commits into from Nov 27, 2023
Merged

liburing #1218

merged 53 commits into from Nov 27, 2023

Conversation

jmillan
Copy link
Member

@jmillan jmillan commented Nov 14, 2023

Enable liburing usage for linux (kernel versions >= 6).

Use liburing to relay incoming RTP to Consumers. This greately reduces the number of system calls as just a single system call is needed to relay the incoming RTP packet to "every" Consumer, opposite to libuv which requires a system call to relay the RTP packet to "each" Consumer.

For efficiency, memory buffers are preallocated holding the data payload being sent.

  • Building mediasoup in a Linux machine with kernel >= 6 will enable the feature.
  • Running mediasoup in a Linux machine with kernel >= 6 will make use of the feature, if it was also enabled in build time.

NOTE: The numbers are really positive. Not only the CPU usage is reduced but it's also more stable.

Enable liburing usage for linux (kernel versions >= 6).

Use liburing to relay incoming RTP to Consumers. This greately reduces the
number of system calls as just a single system call is needed to relay the
incoming RTP packet to "every" Consumer, opposite to libuv which requires a
system call to relay the RTP packet to "each" Consumer.

For efficiency, memory buffers are preallocated holding the data payload
being sent.
@jmillan jmillan requested review from ibc and nazar-pc November 14, 2023 15:43
@nazar-pc
Copy link
Collaborator

Okay, I'm glad you've tested it with positive outcome!
From my experience it is not always faster.

@ibc
Copy link
Member

ibc commented Nov 14, 2023

but it's also more stable

What does this mean exactly?

CHANGELOG.md Outdated Show resolved Hide resolved
@jmillan
Copy link
Member Author

jmillan commented Nov 14, 2023

Okay, I'm glad you've tested it with positive outcome!
From my experience it is not always faster.

In my tests you'll see the difference when larg-ish Routers, but not with small/normal ones. Testing with >200 consumers you'll see a noticeable difference.

@nazar-pc
Copy link
Collaborator

In my tests you'll see the difference when larg-ish Routers, but not with small/normal ones. Testing with >200 consumers you'll see a noticeable difference.

That makes a lot of sense and is to be expected. Squeezing more performance out of the same CPU core is always nice.

@jmillan
Copy link
Member Author

jmillan commented Nov 14, 2023

The numbers are really positive. Not only the CPU usage is reduced but it's also more stable.

What does this mean exactly?

The CPU usage is more stable, it shows less spikes.

worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/handles/TcpConnectionHandle.cpp Outdated Show resolved Hide resolved
worker/src/handles/UdpSocketHandle.cpp Outdated Show resolved Hide resolved
worker/include/DepLibUring.hpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
The binary could have been prebuilt in a linux machine with kernel
version >= 6, but then such image could be run on an older kernel. We
need to check the kernel version in runtime and only enable the feature
when appropriate.
worker/src/handles/UdpSocketHandle.cpp Outdated Show resolved Hide resolved
worker/src/handles/TcpConnectionHandle.cpp Outdated Show resolved Hide resolved
worker/src/handles/UdpSocketHandle.cpp Outdated Show resolved Hide resolved
Copy link
Member

@ibc ibc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it now. Is it ready? Are you gonna add those entries we discussed into the dump data? Or in another PR?

@jmillan
Copy link
Member Author

jmillan commented Nov 21, 2023

Love it now. Is it ready? Are you gonna add those entries we discussed into the dump data? Or in another PR?

Thanks, I'll do few changes in this PR and add those dump data too. I'll notify you once done.

RTP packets are retransmitted in batch, determined by the NACK RTCP
packet. Make use of a single system call to send all Nacked packets.
Take advantage of a single system call when sending multiple compound
packets.
The macro MS_LIBURING_SUPPORTED indicates that liburing capabilities are
contained in the binary.

IsRuntimeSupported() indicates whether the runtime can make use of such
capabilities.
@jmillan
Copy link
Member Author

jmillan commented Nov 21, 2023

@ibc, the initial version of liburing is ready to merge. Can you please take a look at today's 4 commits?

  • Send Nack-ed RTP using liburing
  • Send RTCP compound packets using liburing
  • Rename IsSupported() method for IsRuntimeSupported()
  • LibUring::Dump()

worker/include/DepLibUring.hpp Outdated Show resolved Hide resolved
worker/src/DepLibUring.cpp Outdated Show resolved Hide resolved
@jmillan jmillan merged commit 6821b55 into v3 Nov 27, 2023
36 checks passed
@jmillan jmillan deleted the liburing branch November 27, 2023 16:18
@ashinrot
Copy link

ashinrot commented Dec 5, 2023

This greately reduces the number of system calls as just a single system call is needed to relay the incoming RTP packet to "every" Consumer

Hello, I'm working on udp syscall tunning on my local server, and trying lots of linux feature. IOUring seems to be a good solution, but how about sendmmsg syscall, it seems to be able to reduce the syscall with less code?

@jmillan
Copy link
Member Author

jmillan commented Dec 5, 2023

but how about sendmmsg syscall, it seems to be able to reduce the syscall with less code?

You don't send multiple RTP packets in a raw to the same socket in mediasoup, but the "same" RTP packet from a Producer, to multiple sockets.

sendmmsg is for sending multiple packets to the same socket.

This PR is about using liburing when it's more convenient than libuv.

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

Successfully merging this pull request may close these issues.

None yet

4 participants