-
-
Notifications
You must be signed in to change notification settings - Fork 4
Running multiple instances (stress‐testing etc)
Sergio Ivanuzzo edited this page Feb 11, 2025
·
1 revision
You can write some code for this. For example:
use anyhow::{Result as AnyResult};
use futures::future::join_all;
use tentacli::{Client, RunOptions};
#[tokio::main]
async fn main() -> AnyResult<()> {
let mut tasks = vec![];
for i in 0..200 {
let task = tokio::spawn(async move {
Client::new(CreateOptions { data_storage: None }).run(RunOptions {
external_features: vec![],
account: &format!("bbot{}", i),
config_path: "Config.yml",
dotenv_path: ".env"
}).await?;
});
tasks.push(task);
}
join_all(tasks).await;
Ok(())
}
If you want to share data between instances, you should pass external DataStorage
instance into each of them, smth like:
use std::sync::{Arc, Mutex as SyncMutex};
// ... rest imports
#[tokio::main]
async fn main() -> AnyResult<()> {
let mut tasks = vec![];
let data_storage = Arc::new(SyncMutex::new(DataStorage::default()));
for i in 0..200 {
let task = tokio::spawn(async move {
Client::new(CreateOptions { data_storage: Arc::clone(data_storage) }).run(RunOptions {
// ... options
}).await?;
});
tasks.push(task);
}
join_all(tasks).await;
Ok(())
}
You can use this for stress-testing your server, or you can share some specific logic depends on your needs.