-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⏱️ At a hostcall to get the amount of vcpu time that has passed in th…
…e guest, in milliseconds (#412) This is a proposed extension, to help customers diagnose where their code is spending time. One explicit thing to mention is that while this hostcall limits itself to vcpu time (and thus does not count any time spent blocking on IO, for example), it is based on a time passing rather than cycles, WASM instruction count, or any other timer that is independent of the underlying processor(s) running the code. Thus, the values found should only really be compared to other values captured in the exact same run. --------- Co-authored-by: Jake Champion <[email protected]> Co-authored-by: Cameron Walters (cee-dub) <[email protected]>
- Loading branch information
1 parent
6755370
commit 3192cbf
Showing
21 changed files
with
278 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ mod upstream; | |
mod upstream_async; | ||
mod upstream_dynamic; | ||
mod upstream_streaming; | ||
mod vcpu_time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::{ | ||
common::{Test, TestResult}, | ||
viceroy_test, | ||
}; | ||
use hyper::{Request, Response, StatusCode}; | ||
|
||
viceroy_test!(vcpu_time_getter_works, |is_component| { | ||
let req = Request::get("/") | ||
.header("Accept", "text/html") | ||
.body("Hello, world!") | ||
.unwrap(); | ||
|
||
let resp = Test::using_fixture("vcpu_time_test.wasm") | ||
.adapt_component(is_component) | ||
.backend("slow-server", "/", None, |_| { | ||
std::thread::sleep(std::time::Duration::from_millis(4000)); | ||
Response::builder() | ||
.status(StatusCode::OK) | ||
.body(vec![]) | ||
.unwrap() | ||
}) | ||
.await | ||
.against(req) | ||
.await?; | ||
|
||
assert_eq!(resp.status(), StatusCode::OK); | ||
Ok(()) | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use super::fastly::api::{compute_runtime, types}; | ||
use crate::session::Session; | ||
use std::sync::atomic::Ordering; | ||
|
||
#[async_trait::async_trait] | ||
impl compute_runtime::Host for Session { | ||
async fn get_vcpu_ms(&mut self) -> Result<u64, types::Error> { | ||
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::error::Error; | ||
use crate::session::Session; | ||
use crate::wiggle_abi::fastly_compute_runtime::FastlyComputeRuntime; | ||
use std::sync::atomic::Ordering; | ||
use wiggle::GuestMemory; | ||
|
||
impl FastlyComputeRuntime for Session { | ||
fn get_vcpu_ms(&mut self, _memory: &mut GuestMemory<'_>) -> Result<u64, Error> { | ||
// we internally track microseconds, because our wasmtime tick length | ||
// is too short for ms to work. but we want to shrink this to ms to | ||
// try to minimize timing attacks. | ||
Ok(self.active_cpu_time_us.load(Ordering::SeqCst) / 1000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.