Skip to content

[22974] Improve SHM configuration on large data transports #5725

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

Merged
merged 5 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct SharedMemTransportDescriptor : public PortBasedTransportDescriptor
static constexpr uint32_t shm_default_segment_size = 0;
static constexpr uint32_t shm_default_port_queue_capacity = 512;
static constexpr uint32_t shm_default_healthy_check_timeout_ms = 1000;
static constexpr uint32_t shm_implicit_segment_size = 512 * 1024;

//! Destructor
virtual ~SharedMemTransportDescriptor() = default;
Expand Down
24 changes: 22 additions & 2 deletions src/cpp/rtps/attributes/RTPSParticipantAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ static void setup_large_data_shm_transport(
"TCP for communications on the same host.");
#else
auto descriptor = create_shm_transport(att, options);
auto segment_size = descriptor->segment_size();
if (segment_size == 0)
{
// The user did not configure a buffer size. The correct approach here would
// be to create a socket and querying its output buffer size via get socket option.
// As a workaround, use a value that allows for some big images to be sent.
segment_size = 8500 * 1024; // 8500 KiBytes
descriptor->segment_size(segment_size);
}
// Configure port queue capacity to hold the maximum allocations on the segment
constexpr auto mean_message_size =
SharedMemTransportDescriptor::shm_implicit_segment_size /
SharedMemTransportDescriptor::shm_default_port_queue_capacity;
auto max_allocations = segment_size / mean_message_size;
descriptor->port_queue_capacity(max_allocations);
// Add descriptor to the list of user transports
att.userTransports.push_back(descriptor);

auto shm_loc = fastdds::rtps::SHMLocator::create_locator(0, fastdds::rtps::SHMLocator::Type::UNICAST);
Expand Down Expand Up @@ -351,8 +367,12 @@ void RTPSParticipantAttributes::setup_transports(
}
bool intraprocess_only = is_intraprocess_only(*this);

sendSocketBufferSize = options.sockets_buffer_size;
listenSocketBufferSize = options.sockets_buffer_size;
// Override the default send and receive buffer sizes when set in the options
if (options.sockets_buffer_size != 0)
{
sendSocketBufferSize = options.sockets_buffer_size;
listenSocketBufferSize = options.sockets_buffer_size;
}

switch (transports)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace fastdds {
namespace rtps {

// TODO(Adolfo): Calculate this value from UDP sockets buffers size.
static constexpr uint32_t shm_default_segment_size = 512 * 1024;
static constexpr uint32_t shm_default_segment_size = SharedMemTransportDescriptor::shm_implicit_segment_size;

TransportInterface* SharedMemTransportDescriptor::create_transport() const
{
Expand Down
Loading