Skip to content

Commit

Permalink
Limit threads per zenoh session (#95)
Browse files Browse the repository at this point in the history
* Limit threads per zenoh session and in router config

Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund authored Jan 22, 2024
1 parent 0e7a380 commit 06f29d0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_ROUTER_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@
backoff: 100,
// Number of threads dedicated to transmission
// By default, the number of threads is calculated as follows: 1 + ((#cores - 1) / 4)
// threads: 4,
// We limit the number of threads that the zenoh session can spin to 1.
// Without this limit, applications with multiple zenoh sessions can
// encounter system resource errors when trying to create new threads.
// Once zenoh migrates to relying on tokio for its async runtime,
// see https://github.com/eclipse-zenoh/zenoh/pull/566, we can consider
// removing these flags since with tokio, zenoh can better manage the threads it spins
// with the help of thread pools.
threads: 1,
},
},
/// Configure the zenoh RX parameters of a link
Expand Down
10 changes: 10 additions & 0 deletions rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@
/// 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)
// We limit the number of threads that the zenoh session can spin to 1.
// Without this limit, applications with multiple zenoh sessions can
// encounter system resource errors when trying to create new threads.
// Once zenoh migrates to relying on tokio for its async runtime,
// see https://github.com/eclipse-zenoh/zenoh/pull/566, we can consider
// removing these flags since with tokio, zenoh can better manage the threads it spins
// with the help of thread pools.
threads: 1,
},
/// Configure the zenoh RX parameters of a link
rx: {
Expand Down
16 changes: 16 additions & 0 deletions zenoh_c_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,25 @@ 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 limit the number of threads that
# the zenoh session can spin via the session config as well as the ASYNC_STD_THREAD_COUNT
# environment variable. Without this limit, applications with multiple zenoh sessions can
# encounter system resource errors when trying to create new threads.
# Once zenoh migrates to relying on tokio for its async runtime,
# see https://github.com/eclipse-zenoh/zenoh/pull/566, we can consider
# removing these flags since with tokio, zenoh can better manage the threads it spins
# with the help of thread pools.
# Note: We separate the two args needed for cargo with "$<SEMICOLON>" 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$<SEMICOLON>--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")
Expand Down

0 comments on commit 06f29d0

Please sign in to comment.