Reputation: 11
For reasons, I am trying to write a program to maximize Zookeeper throughput of znode creation. Here is the rust program I have currently:
#![allow(dead_code)]
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
use zookeeper::{Acl, CreateMode, WatchedEvent, Watcher, ZooKeeper};
struct DefaultWatcher;
impl Watcher for DefaultWatcher {
fn handle(&self, _ev: WatchedEvent) {}
}
fn main() {
ephemeral_sequential_test();
}
fn ephemeral_sequential_test() {
let duration = Duration::new(10, 0);
let start_time = Instant::now();
let zk = Arc::new(
ZooKeeper::connect("127.0.0.1:2181", Duration::from_secs(10), DefaultWatcher)
.expect("Failed to connect to ZooKeeper"),
);
let mut handles = Vec::new();
const BENCHMARK_PATH: &str = "/benchmark";
// create benchmark node if it doesn't exist
if zk.exists(BENCHMARK_PATH, false).unwrap().is_none() {
zk.create(
BENCHMARK_PATH,
vec![],
Acl::open_unsafe().clone(),
CreateMode::Persistent,
)
.expect("Failed to create parent dir");
}
for _ in 0..1500 {
let zk_clone = Arc::clone(&zk);
let start_time_clone = start_time;
let handle = thread::spawn(move || {
while start_time_clone.elapsed() < duration {
// Create an ephemeral sequential znode
zk_clone
.create(
&format!("{}/node_", BENCHMARK_PATH),
vec![],
Acl::open_unsafe().clone(),
CreateMode::PersistentSequential,
)
.expect("Error creating znode");
}
});
handles.push(handle);
}
// Wait for all threads to complete
for handle in handles {
handle.join().unwrap();
}
thread::sleep(Duration::from_secs(1));
// Get number of children and print them
let num_children = zk.get_children(BENCHMARK_PATH, false).unwrap().len();
println!("Total znodes added: {}", num_children);
println!(
"Operations per second: {:.2}",
num_children as f64 / duration.as_secs_f64()
);
}
So far, I've tried different language libraries (go, java), switching to Tokio-zk (for async operations), and making changes to zoo.cfg. They all seem to either hurt performance or have no effect.
I've gotten to about 70k znodes per second, but only through increasing the # of threads. I've tried to spawn more threads, but it seems it just doesn't let me past ~1000 (it doesn't throw errors, it just has no effect). I've tried increasing my ulimit but it doesn't do anything. I think finding a way to increase the amount of threads I can create would help, but I can't figure out how to do so (macos).
Does anyone have any ideas on stuff to implement or things I should change to increase znode throughput? Any help would be appreciated!
Upvotes: 1
Views: 38