Skip to content

Commit

Permalink
make SHM enabled by default in Config (#1312)
Browse files Browse the repository at this point in the history
* make SHM enabled by default in Config

* [skip ci] add SHM description in the config file

* review fixes: assert -> unwrap
  • Loading branch information
yellowhatter authored Aug 14, 2024
1 parent 5b628ac commit 0e2f78a
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 68 deletions.
9 changes: 7 additions & 2 deletions DEFAULT_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,14 @@
server_name_verification: null,
},
},
/// Shared memory configuration
/// Shared memory configuration.
/// NOTE: shared memory can be used only if zenoh is compiled with "shared-memory" feature, otherwise
/// settings in this section have no effect.
shared_memory: {
enabled: false,
/// A probing procedure for shared memory is performed upon session opening. To enable zenoh to operate
/// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
/// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
enabled: true,
},
auth: {
/// The configuration of authentication.
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Default for LinkRxConf {
#[allow(clippy::derivable_impls)]
impl Default for ShmConf {
fn default() -> Self {
Self { enabled: false }
Self { enabled: true }
}
}

Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_get_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ async fn main() {
// initiate logging
zenoh::try_init_log_from_env();

let (mut config, selector, mut payload, target, timeout) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, selector, mut payload, target, timeout) = parse_args();

println!("Opening session...");
let session = zenoh::open(config).await.unwrap();
Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_ping_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ fn main() {
// Initiate logging
zenoh::try_init_log_from_env();

let (mut config, warmup, size, n) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_ping_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, warmup, size, n) = parse_args();

let session = zenoh::open(config).wait().unwrap();

Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ fn main() {
// initiate logging
zenoh::try_init_log_from_env();

let (mut config, express) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_ping_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, express) = parse_args();

let session = zenoh::open(config).wait().unwrap().into_arc();

Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_pub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ async fn main() -> Result<(), ZError> {
// Initiate logging
zenoh::try_init_log_from_env();

let (mut config, path, payload) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, path, payload) = parse_args();

println!("Opening session...");
let session = zenoh::open(config).await.unwrap();
Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_pub_shm_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ use zenoh_examples::CommonArgs;
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
let (mut config, sm_size, size) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm_thr` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, sm_size, size) = parse_args();

let z = zenoh::open(config).await.unwrap();

Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ async fn main() {
// initiate logging
zenoh::try_init_log_from_env();

let (mut config, key_expr, payload, complete) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_get_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, key_expr, payload, complete) = parse_args();

println!("Opening session...");
let session = zenoh::open(config).await.unwrap();
Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_queryable_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ async fn main() {
// initiate logging
zenoh::try_init_log_from_env();

let (mut config, key_expr, payload, complete) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_get_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, key_expr, payload, complete) = parse_args();

println!("Opening session...");
let session = zenoh::open(config).await.unwrap();
Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();

let (mut config, key_expr) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, key_expr) = parse_args();

println!("Opening session...");
let session = zenoh::open(config).await.unwrap();
Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_sub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();

let (mut config, key_expr) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, key_expr) = parse_args();

println!("Opening session...");
let session = zenoh::open(config).await.unwrap();
Expand Down
7 changes: 1 addition & 6 deletions examples/examples/z_sub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ fn main() {
// initiate logging
zenoh::try_init_log_from_env();

let (mut config, m, n) = parse_args();

// A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm_thr` to operate
// over shared memory (and to not fallback on network mode), shared memory needs to be enabled also on the
// subscriber side. By doing so, the probing procedure will succeed and shared memory will operate as expected.
config.transport.shared_memory.set_enabled(true).unwrap();
let (config, m, n) = parse_args();

let session = zenoh::open(config).wait().unwrap();

Expand Down
8 changes: 3 additions & 5 deletions zenoh/tests/shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use zenoh::{
pubsub::Reliability,
qos::CongestionControl,
shm::{
BlockOn, GarbageCollect, PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID,
zshm, BlockOn, GarbageCollect, PosixShmProviderBackend, ShmProviderBuilder,
POSIX_PROTOCOL_ID,
},
Session,
};
Expand All @@ -52,7 +53,6 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) {
)
.unwrap();
config.scouting.multicast.set_enabled(Some(false)).unwrap();
config.transport.shared_memory.set_enabled(true).unwrap();
println!("[ ][01a] Opening peer01 session: {:?}", endpoints);
let peer01 = ztimeout!(zenoh::open(config)).unwrap();

Expand All @@ -68,7 +68,6 @@ async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) {
)
.unwrap();
config.scouting.multicast.set_enabled(Some(false)).unwrap();
config.transport.shared_memory.set_enabled(true).unwrap();
println!("[ ][02a] Opening peer02 session: {:?}", endpoints);
let peer02 = ztimeout!(zenoh::open(config)).unwrap();

Expand All @@ -84,7 +83,6 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session,
.set(vec![endpoint01.parse().unwrap()])
.unwrap();
config.scouting.multicast.set_enabled(Some(true)).unwrap();
config.transport.shared_memory.set_enabled(true).unwrap();
println!("[ ][01a] Opening peer01 session: {}", endpoint01);
let peer01 = ztimeout!(zenoh::open(config)).unwrap();

Expand All @@ -95,7 +93,6 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session,
.set(vec![endpoint02.parse().unwrap()])
.unwrap();
config.scouting.multicast.set_enabled(Some(true)).unwrap();
config.transport.shared_memory.set_enabled(true).unwrap();
println!("[ ][02a] Opening peer02 session: {}", endpoint02);
let peer02 = ztimeout!(zenoh::open(config)).unwrap();

Expand Down Expand Up @@ -128,6 +125,7 @@ async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Re
.declare_subscriber(&key_expr)
.callback(move |sample| {
assert_eq!(sample.payload().len(), size);
let _ = sample.payload().deserialize::<&zshm>().unwrap();
c_msgs.fetch_add(1, Ordering::Relaxed);
}))
.unwrap();
Expand Down

0 comments on commit 0e2f78a

Please sign in to comment.