Skip to content

Commit 8ee4c02

Browse files
committed
fix: profile server in bench_runner_server
1 parent 137ce9c commit 8ee4c02

2 files changed

Lines changed: 40 additions & 12 deletions

File tree

src/bin/argusdb.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ struct Args {
5757
#[arg(long, default_value_t = false)]
5858
no_log: bool,
5959

60+
/// Profile output file
61+
#[arg(long)]
62+
profile: Option<String>,
63+
6064
/// Print help
6165
#[arg(long, action = clap::ArgAction::Help)]
6266
help: Option<bool>,
@@ -296,6 +300,8 @@ async fn main() {
296300
tracing::subscriber::set_global_default(subscriber).unwrap();
297301
let settings: Settings = builder.build().unwrap().try_deserialize().unwrap();
298302

303+
let profile_guard = argusdb::bench_utils::start_profiling(&args.profile);
304+
299305
let log_threshold = if settings.no_log {
300306
None
301307
} else {
@@ -316,12 +322,30 @@ async fn main() {
316322
let listener = TcpListener::bind(&server_addr).await.unwrap();
317323
info!("ArgusDB server listening on {}", server_addr);
318324

325+
let mut sigterm =
326+
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).unwrap();
327+
let mut sigint =
328+
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::interrupt()).unwrap();
329+
319330
loop {
320-
let (socket, _) = listener.accept().await.unwrap();
321331
let processor = processor.clone();
322-
323-
tokio::spawn(async move {
324-
let _ = process_socket(socket, None, processor).await;
325-
});
332+
tokio::select! {
333+
res = listener.accept() => {
334+
let (socket, _) = res.unwrap();
335+
tokio::spawn(async move {
336+
let _ = process_socket(socket, None, processor).await;
337+
});
338+
}
339+
_ = sigterm.recv() => {
340+
info!("Received SIGTERM, shutting down");
341+
break;
342+
}
343+
_ = sigint.recv() => {
344+
info!("Received SIGINT, shutting down");
345+
break;
346+
}
347+
}
326348
}
349+
350+
argusdb::bench_utils::save_profile(profile_guard, &args.profile);
327351
}

src/bin/bench_runner_server.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#[global_allocator]
22
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
33

4-
use argusdb::bench_utils::{
5-
Args, Query, load_queries, run_measurement, save_profile, start_profiling,
6-
};
4+
use argusdb::bench_utils::{Args, Query, load_queries, run_measurement};
75
use clap::Parser;
86
use rand::prelude::IndexedRandom;
97
use std::fs;
@@ -26,7 +24,12 @@ struct ServerGuard {
2624

2725
impl Drop for ServerGuard {
2826
fn drop(&mut self) {
29-
let _ = self.child.kill();
27+
let pid = self.child.id();
28+
let _ = Command::new("kill")
29+
.arg("-s")
30+
.arg("TERM")
31+
.arg(pid.to_string())
32+
.status();
3033
let _ = self.child.wait();
3134
}
3235
}
@@ -104,6 +107,10 @@ async fn main() {
104107
command.arg("--no-log");
105108
}
106109

110+
if let Some(profile) = &args.profile {
111+
command.arg("--profile").arg(profile);
112+
}
113+
107114
let child = command
108115
.stdout(Stdio::inherit())
109116
.stderr(Stdio::inherit())
@@ -193,7 +200,6 @@ async fn main() {
193200
.await;
194201

195202
println!("Starting measurement for {} seconds...", args.duration);
196-
let guard = start_profiling(&args.profile);
197203

198204
let results = run_measurement(
199205
args.concurrency,
@@ -205,8 +211,6 @@ async fn main() {
205211
)
206212
.await;
207213

208-
save_profile(guard, &args.profile);
209-
210214
println!("Results:");
211215
for (name, (count, total_time)) in results {
212216
let avg = if count > 0 {

0 commit comments

Comments
 (0)