Skip to content

Commit 430609d

Browse files
Improve SHM configuration on large data transports (#5725)
* Refs #22974. Only override buffer sizes when they are 0. Signed-off-by: Miguel Company <[email protected]> * Refs #22974. Increase segment size on large data / easy mode. Signed-off-by: Miguel Company <[email protected]> * Refs #22974. Add constexpr `SharedMemTransportDescriptor::shm_implicit_segment_size` Signed-off-by: Miguel Company <[email protected]> * Refs #22974. Setup port_queue_capacity. Signed-off-by: Miguel Company <[email protected]> * Refs #22974. Give priority to buffer size in options. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]>
1 parent a020c1d commit 430609d

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

include/fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct SharedMemTransportDescriptor : public PortBasedTransportDescriptor
5252
static constexpr uint32_t shm_default_segment_size = 0;
5353
static constexpr uint32_t shm_default_port_queue_capacity = 512;
5454
static constexpr uint32_t shm_default_healthy_check_timeout_ms = 1000;
55+
static constexpr uint32_t shm_implicit_segment_size = 512 * 1024;
5556

5657
//! Destructor
5758
virtual ~SharedMemTransportDescriptor() = default;

src/cpp/rtps/attributes/RTPSParticipantAttributes.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ static void setup_large_data_shm_transport(
228228
"TCP for communications on the same host.");
229229
#else
230230
auto descriptor = create_shm_transport(att, options);
231+
auto segment_size = descriptor->segment_size();
232+
if (segment_size == 0)
233+
{
234+
// The user did not configure a buffer size. The correct approach here would
235+
// be to create a socket and querying its output buffer size via get socket option.
236+
// As a workaround, use a value that allows for some big images to be sent.
237+
segment_size = 8500 * 1024; // 8500 KiBytes
238+
descriptor->segment_size(segment_size);
239+
}
240+
// Configure port queue capacity to hold the maximum allocations on the segment
241+
constexpr auto mean_message_size =
242+
SharedMemTransportDescriptor::shm_implicit_segment_size /
243+
SharedMemTransportDescriptor::shm_default_port_queue_capacity;
244+
auto max_allocations = segment_size / mean_message_size;
245+
descriptor->port_queue_capacity(max_allocations);
246+
// Add descriptor to the list of user transports
231247
att.userTransports.push_back(descriptor);
232248

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

354-
sendSocketBufferSize = options.sockets_buffer_size;
355-
listenSocketBufferSize = options.sockets_buffer_size;
370+
// Override the default send and receive buffer sizes when set in the options
371+
if (options.sockets_buffer_size != 0)
372+
{
373+
sendSocketBufferSize = options.sockets_buffer_size;
374+
listenSocketBufferSize = options.sockets_buffer_size;
375+
}
356376

357377
switch (transports)
358378
{

src/cpp/rtps/transport/shared_mem/SharedMemTransport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace fastdds {
4848
namespace rtps {
4949

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

5353
TransportInterface* SharedMemTransportDescriptor::create_transport() const
5454
{

0 commit comments

Comments
 (0)