Closed
Description
- why is the write so slow at 2500 req/s? how to make it send as fast as possible?
- any mechanism to synchronize reader and writer like https://github.com/cloudwego/shmipc-go ? how to coordinate the read and write ipc?
thx for the great work by the way
mod common;
use common::HelloWorld;
use mmap_sync::synchronizer::Synchronizer;
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
use std::thread;
use std::time::{Duration, Instant};
fn main() {
let mut synchronizer = Synchronizer::new("/tmp/hello_world".as_ref());
let data = HelloWorld {
version: 7,
messages: vec!["Hello".to_string(), "World".to_string(), "!".to_string()],
};
let request_count = Arc::new(AtomicUsize::new(0));
let request_count_clone = Arc::clone(&request_count);
// Spawn a thread to print requests per second
thread::spawn(move || {
let mut start = Instant::now();
loop {
// Check if a second has passed
if start.elapsed() >= Duration::from_secs(1) {
let requests = request_count_clone.swap(0, Ordering::Relaxed);
println!("Server requests per second: {}", requests);
start = Instant::now();
}
// Sleep for a short duration to yield CPU
thread::sleep(Duration::from_millis(10));
}
});
loop {
// Write data to shared memory without any delay
synchronizer.write(&data, Duration::from_nanos(1)).expect("failed to write data");
request_count.fetch_add(1, Ordering::Relaxed);
}
}
Metadata
Metadata
Assignees
Labels
No labels