From cb682f85844811a264a9d63c0574c32493044a0f Mon Sep 17 00:00:00 2001 From: Yadunund Date: Sat, 20 Jan 2024 12:26:45 +0800 Subject: [PATCH] Limit threads per zenoh session Signed-off-by: Yadunund --- .../config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5 | 3 +++ zenoh_c_vendor/CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5 b/rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5 index 43550e1d..0d8528a2 100644 --- a/rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5 +++ b/rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5 @@ -185,6 +185,9 @@ /// Higher values lead to a more aggressive batching but it will introduce additional latency. backoff: 100, }, + // Number of threads dedicated to transmission + // By default, the number of threads is calculated as follows: 1 + ((#cores - 1) / 4) + threads: 1, }, /// Configure the zenoh RX parameters of a link rx: { diff --git a/zenoh_c_vendor/CMakeLists.txt b/zenoh_c_vendor/CMakeLists.txt index 2240ba87..c90c0a5f 100644 --- a/zenoh_c_vendor/CMakeLists.txt +++ b/zenoh_c_vendor/CMakeLists.txt @@ -10,9 +10,24 @@ endif() find_package(ament_cmake REQUIRED) find_package(ament_cmake_vendor_package REQUIRED) +# Disable default features and only enable tcp transport for zenoh. This reduces +# build time but more importantly allows us to set the number of threads that +# the zenoh session can spin via session config as well as ASYNC_STD_THREAD_COUNT +# envar. Without this limit, applications with multiple zenoh sessions can +# encounter to system resource limits when trying to create new threads. +# Once zenoh migrates to relying on tokio for async runtime, we can consider +# removing these flags since tokio allows better control over threads spawned with +# the help of thread pools. +# Note: We separate the two args needed for cargo with "$" and not ";" as the +# latter is a list separater in cmake and hence the string will be split into two +# when expanded. +set(ZENOHC_CARGO_FLAGS "--no-default-features$--features=zenoh/transport_tcp") + ament_vendor(zenoh_c_vendor VCS_URL https://github.com/eclipse-zenoh/zenoh-c.git VCS_VERSION 0.10.1-rc + CMAKE_ARGS + "-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}" ) # set(INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-prefix/install")