-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhancement(remap transform): add get_hostname
function
#6141
Conversation
Signed-off-by: Kirill Fomichev <[email protected]>
Signed-off-by: Kirill Fomichev <[email protected]>
Signed-off-by: Kirill Fomichev <[email protected]>
I'll defer to @JeanMertz on that, but my gut says yes. |
+1 - 500 ms is way too slow. |
FTR criterion reports 150ns (509 instructions) on my Linux system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 - 500 ms is way too slow.
Just to clarify; the measurements are showing ns and us per operation, and 500 ms for the total duration of 1 million runs.
I think this should be fine to ship as-is, and once https://github.com/timberio/vector/issues/6145 lands, we can add the caching optimization to this function to further improve its performance.
Signed-off-by: Kirill Fomichev <[email protected]>
Signed-off-by: Kirill Fomichev <[email protected]>
Signed-off-by: Kirill Fomichev <[email protected]>
@JeanMertz thanks for the improvement comments. I added cache with
Code:use criterion::{criterion_group, criterion_main, Criterion};
use std::cell::RefCell;
use std::time::{Duration, Instant};
thread_local! {
static HOSTNAME: RefCell<(Instant, String)> = RefCell::new((Instant::now(), get_hostname_inner()));
}
pub fn get_hostname_inner() -> String {
hostname::get().unwrap().into_string().unwrap()
}
pub fn get_hostname() -> String {
HOSTNAME.with(|pair| {
let mut pair = pair.borrow_mut();
let now = Instant::now();
if pair.0 < now {
pair.0 = now + Duration::from_millis(10);
pair.1 = get_hostname_inner();
}
pair.1.clone()
})
}
fn bench(c: &mut Criterion) {
let mut group = c.benchmark_group("get_hostname");
group.bench_function("get_hostname_inner", |b| b.iter(|| get_hostname_inner()));
group.bench_function("get_hostname", |b| b.iter(|| get_hostname()));
group.finish()
}
criterion_group!(get_hostname_bench, bench);
criterion_main!(get_hostname_bench); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might back out the caching for now in-lieu of taking a holistic look at it in https://github.com/timberio/vector/issues/6145 . 500 ns seems plenty fast for now.
I think it raises questions around cache expiration and how users would ensure they are always getting the most up-to-date value if they decide that is worth the performance trade-off.
Otherwise this looks good to me.
Signed-off-by: Kirill Fomichev <[email protected]>
Signed-off-by: Kirill Fomichev <[email protected]>
Signed-off-by: Kirill Fomichev <[email protected]>
Close #5800
Performance:
cargo run --release
:515.736747ms
(~500ns/op
)13.908112518s
(~14us/op
)@binarylogic how you think, should we use some cache?