add chrono for benchmarking
This commit is contained in:
+20
-7
@@ -6,21 +6,34 @@ mod worker;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
|
||||
use chrono::prelude::*;
|
||||
use database::init_database_pool;
|
||||
use model::{Job, JobAction};
|
||||
use worker::Manager;
|
||||
use worker::{Manager, WorkerStatus};
|
||||
|
||||
fn main() {
|
||||
let now: DateTime<Utc> = Utc::now();
|
||||
|
||||
init_database_pool();
|
||||
|
||||
let mut m: Manager<Job> = Manager::new("deploy");
|
||||
m.launch_workers(5);
|
||||
let mut deployer: Manager<Job> = Manager::new("deploy");
|
||||
deployer.launch_workers(10);
|
||||
|
||||
for i in 0..50 {
|
||||
for i in 0..5000 {
|
||||
let job = Job::new(i, JobAction::MegaportDeploy);
|
||||
m.add_runner(job);
|
||||
deployer.add_runner(job);
|
||||
}
|
||||
|
||||
let wait = time::Duration::from_secs(2);
|
||||
thread::sleep(wait);
|
||||
let wait = time::Duration::from_millis(100);
|
||||
|
||||
while !deployer.healthcheck(WorkerStatus::Pending) {
|
||||
thread::sleep(wait);
|
||||
}
|
||||
|
||||
let elapsed = Utc::now() - now;
|
||||
println!(
|
||||
"deployment done in : {}.{}s",
|
||||
elapsed.num_seconds(),
|
||||
elapsed.num_milliseconds(),
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
mod worker;
|
||||
|
||||
pub use worker::{Manager, Queue};
|
||||
pub use worker::{Manager, Queue, WorkerStatus};
|
||||
|
||||
@@ -106,8 +106,7 @@ impl<T: Runner + std::marker::Send + 'static> Manager<T> {
|
||||
self.queue.not_empty.notify_one();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn healthcheck(&self, target: WorkerStatus) -> bool {
|
||||
pub fn healthcheck(&self, target: WorkerStatus) -> bool {
|
||||
for w in &self.workers {
|
||||
if w.lock().unwrap().get_status() != target {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user