Skip to content
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

Add 'shared_memory' config in shm examples #598

Merged
merged 2 commits into from
Nov 23, 2023
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
10 changes: 6 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@
z_storage -k demo/**
```

### z_pub_shm & z_sub_shm
### z_pub_shm & z_sub

A pub/sub example involving the shared-memory feature.
Note that on subscriber side, the same `z_sub` example than for non-shared-memory example is used.

Typical Subscriber usage:
```bash
z_sub_shm
z_sub
```

Typical Publisher usage:
Expand Down Expand Up @@ -188,16 +189,17 @@
z_ping 1024
```

### z_pub_shm_thr & z_sub_shm_thr
### z_pub_shm_thr & z_sub_thr

Pub/Sub throughput test involving the shared-memory feature.
This example allows performing throughput measurements between a publisher performing
put operations with the shared-memory feature and a subscriber receiving notifications
of those puts.
Note that on subscriber side, the same `z_sub_thr` example than for non-shared-memory example is used.

Typical Subscriber usage:
```bash
z_sub_shm_thr
z_sub_thr
```

Typical Publisher usage:
Expand Down
9 changes: 7 additions & 2 deletions examples/examples/z_pub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ async fn main() -> Result<(), zenoh::Error> {
// Initiate logging
env_logger::init();

let (config, path, value) = parse_args();
let (mut config, path, value) = 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();

println!("Opening session...");
let session = zenoh::open(config).res().await.unwrap();
Expand All @@ -39,6 +44,7 @@ async fn main() -> Result<(), zenoh::Error> {
let publisher = session.declare_publisher(&path).res().await.unwrap();

for idx in 0..(K * N as u32) {
sleep(Duration::from_secs(1)).await;
let mut sbuf = match shm.alloc(1024) {
Ok(buf) => buf,
Err(_) => {
Expand Down Expand Up @@ -88,7 +94,6 @@ async fn main() -> Result<(), zenoh::Error> {
let defrag = shm.defragment();
println!("De-framented {defrag} bytes");
}
// sleep(Duration::from_millis(100)).await;
// Dropping the SharedMemoryBuf means to free it.
drop(sbuf);
}
Expand Down
7 changes: 6 additions & 1 deletion examples/examples/z_pub_shm_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ use zenoh::shm::SharedMemoryManager;
async fn main() {
// initiate logging
env_logger::init();
let (config, sm_size, size) = parse_args();
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 z = zenoh::open(config).res().await.unwrap();
let id = z.zid();
Expand Down
7 changes: 6 additions & 1 deletion examples/examples/z_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ async fn main() {
// Initiate logging
env_logger::init();

let (config, key_expr) = parse_args();
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();

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

let (config, m, n) = parse_args();
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 session = zenoh::open(config).res().unwrap();

Expand Down
Loading