Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/xtask-llm-benchmark/src/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod templates;
pub mod types;
pub(crate) mod utils;

pub use publishers::{DotnetPublisher, Publisher, SpacetimeRustPublisher, TypeScriptPublisher};
pub use publishers::{DotnetPublisher, PublishedDatabase, Publisher, SpacetimeRustPublisher, TypeScriptPublisher};
pub use runner::TaskRunner;
pub use types::{RunOutcome, TaskPaths};
pub use utils::bench_route_concurrency;
69 changes: 62 additions & 7 deletions tools/xtask-llm-benchmark/src/bench/publishers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,63 @@ fn strip_ansi_codes(s: &str) -> Cow<'_, str> {
/* Shared */
/* -------------------------------------------------------------------------- */

pub struct PublishedDatabase {
host_url: String,
db: String,
// Keep the publishing CLI session alive so deletion uses the database
// owner's credentials without sharing mutable CLI state across routes.
cli_root: CliRootDir,
deleted: bool,
}

impl PublishedDatabase {
fn new(host_url: &str, db: String, cli_root: CliRootDir) -> Self {
Self {
host_url: host_url.to_owned(),
db,
cli_root,
deleted: false,
}
}

fn delete_inner(&self) -> Result<()> {
let mut cmd = spacetime_cmd(&self.cli_root);
cmd.arg("delete")
.arg("-y")
.arg("--no-config")
.arg("--server")
.arg(&self.host_url)
.arg(&self.db);
run(&mut cmd, "spacetime delete").with_context(|| {
format!(
"failed to clean up benchmark database `{}` on {}",
self.db, self.host_url
)
})
}

pub fn delete(mut self) -> Result<()> {
self.delete_inner()?;
self.deleted = true;
Ok(())
}
}

impl Drop for PublishedDatabase {
fn drop(&mut self) {
if !self.deleted
&& let Err(error) = self.delete_inner()
{
eprintln!(
"[cleanup] failed to delete benchmark database `{}` during fallback cleanup: {error:#}",
self.db
);
}
}
}

pub trait Publisher: Send + Sync {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<()>;
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<PublishedDatabase>;
}

/// Check if the process was killed by a signal (e.g., SIGSEGV = 11)
Expand Down Expand Up @@ -342,7 +397,7 @@ impl DotnetPublisher {
}

impl Publisher for DotnetPublisher {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<()> {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<PublishedDatabase> {
if !source.exists() {
bail!("no source: {}", source.display());
}
Expand Down Expand Up @@ -370,7 +425,7 @@ impl Publisher for DotnetPublisher {
Self::configure_dotnet_env(&mut pubcmd);
run(&mut pubcmd, "spacetime publish (csharp)")?;

Ok(())
Ok(PublishedDatabase::new(host_url, db, cli_root))
}
}
/* -------------------------------------------------------------------------- */
Expand All @@ -390,7 +445,7 @@ impl SpacetimeRustPublisher {
}

impl Publisher for SpacetimeRustPublisher {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<()> {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<PublishedDatabase> {
if !source.exists() {
bail!("no source: {}", source.display());
}
Expand All @@ -416,7 +471,7 @@ impl Publisher for SpacetimeRustPublisher {
"spacetime publish",
)?;

Ok(())
Ok(PublishedDatabase::new(host_url, db, cli_root))
}
}

Expand All @@ -437,7 +492,7 @@ impl TypeScriptPublisher {
}

impl Publisher for TypeScriptPublisher {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<()> {
fn publish(&self, host_url: &str, source: &Path, module_name: &str) -> Result<PublishedDatabase> {
if !source.exists() {
bail!("no source: {}", source.display());
}
Expand Down Expand Up @@ -539,6 +594,6 @@ impl Publisher for TypeScriptPublisher {
}
run(&mut publish_cmd, "spacetime publish (typescript)")?;

Ok(())
Ok(PublishedDatabase::new(host_url, db, cli_root))
}
}
Loading
Loading