risingwavelabs / await-tree Goto Github PK
View Code? Open in Web Editor NEWGenerate accurate and informative tree dumps of asynchronous tasks.
License: Apache License 2.0
Generate accurate and informative tree dumps of asynchronous tasks.
License: Apache License 2.0
I have noticed there is a TODO in Registery::register
:
Lines 79 to 81 in 334b563
I guess this will make spawning an task become O(m)
operation where m
is the current running task. Perhaps we can add a new config like gc_throttle_duration: Option<Duration>
(default None
). Once it become Some
, the registry will maintain the coarse instant of last GC, new register
callls within this period again won't trigger GC anymore.
I have written a simple bench to test that spawns many background tasks(Even not really usual in real word, this case was usually used to show how coroutines are lighter that threads):
fn traced_multi_thread(size: usize) {
let pool = tokio::runtime::Builder::new_multi_thread()
.enable_time()
.build()
.unwrap();
let futs = (0..size)
.map(|_| {
pool.spawn(root!(async {
tokio::time::sleep(std::time::Duration::from_millis(100)).await
}))
})
.collect::<Vec<_>>();
pool.block_on(futures::future::join_all(futs));
}
Where root
is a simple macro registers the current line to the register
function. What it did like:
pub fn root<T>(
fut: impl Future<Output = T>,
) -> impl Future<Output = T> {
let id = TID.fetch_add(1, SeqCst);
REG.lock().unwrap().register(id, concat!(file!(), ":", line!(), ",", column!())).instrument(fut)
}
The result shows comparing to the baseline with 10,000 tasks , there was a 3x performance regression, which is huge I think.
running 2 tests
test bench_async_trace::multi_thread::baseline_multi_thread_10000 ... bench: 101,856,955 ns/iter (+/- 345,245)
test bench_async_trace::multi_thread::traced_multi_thread_10000 ... bench: 308,596,986 ns/iter (+/- 3,973,652)
I haven't do further works now. If somewhere I'm wrong during benching or something else please let me know. If the new option is acceptable I'm glad to do further perfing to test whether the solution is effect and providing a patch.
Hi, OpenDAL is currently developing an AwaitTreeLayer to give our users the ability to dump the execution tree at runtime: apache/opendal#2623
The missing part here is that how can we add instrument for functions returns Poll<T>
? For example, AsyncRead
will have API like the following:
pub trait AsyncRead {
// Required method
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>;
Can we add instrument for every poll operations?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.