ITPub博客

首页 > 数据库 > 数据库开发技术 > 【Rust日报】2022-11-01 async-backtrace 发布

【Rust日报】2022-11-01 async-backtrace 发布

原创 数据库开发技术 作者:Rust语言中文社区 时间:2022-11-01 23:41:45 0 删除 编辑

async-backtrace 发布

tokio 官方团队近日发布了 async-backtrace 的初个版本,旨在让开发者能够高效地追踪应用中异步任务的状态。
使用步骤如下:
  1. 首先将该 crate 加入到 Cargo.toml 文件中:
[dependencies]
async-backtrace = "0.2"
  1. 使用 #[async_backtrace::framed] 标注一个异步函数可用于追踪,使用 taskdump_tree 以树的形式输出当前所有被追踪的任务状态:
#[tokio::main(flavor = "current_thread")]
async fn main() {
tokio::select! {
// run the following branches in order of their appearance
biased;

// spawn task #1
_ = tokio::spawn(foo()) => { unreachable!() }

// spawn task #2
_ = tokio::spawn(foo()) => { unreachable!() }

// print the running tasks
_ = tokio::spawn(async {}) => {
println!("{}", async_backtrace::taskdump_tree(true));
}
};
}

#[async_backtrace::framed]
async fn foo() {
bar().await;
}

#[async_backtrace::framed]
async fn bar() {
baz().await;
}

#[async_backtrace::framed]
async fn baz() {
std::future::pending::<()>().await
}
  1. 运行上述代码示例,会输出以下内容
╼ multiple::foo::{{closure}} at backtrace/examples/multiple.rs:22:1
└╼ multiple::bar::{{closure}} at backtrace/examples/multiple.rs:27:1
└╼ multiple::baz::{{closure}} at backtrace/examples/multiple.rs:32:1
╼ multiple::foo::{{closure}} at backtrace/examples/multiple.rs:22:1
└╼ multiple::bar::{{closure}} at backtrace/examples/multiple.rs:27:1
└╼ multiple::baz::{{closure}} at backtrace/examples/multiple.rs:32:1
需要注意的是,async-backtrace 才刚刚起步,如果遇到任何问题,欢迎大家在 github issue 上进行反馈
  • 仓库地址: https://github.com/tokio-rs/tokio-metrics
  • 原文链接: https://tokio.rs/blog/2022-10-announcing-async-backtrace

astro-float:一个任意精度的浮点数库

作者 stencillogic 近日发布了使用纯 rust 实现的一个任意精度的浮点数库 astro-float,采用了很多广泛使用的算法,例如 Toom-3,Schönhage–Strassen 等大数乘法。
此类完全使用 Rust 实现的浮点数运算库还有 ibig、num-bigint,相比于 rug 这类对于 GMP 的绑定库,它们最大的好处是完全用 Rust 实现,不依赖 std,但是在性能上仍有差距。
更详细的 benchmark 结果可以参考以下文章:
  • bigint benchmark: https://github.com/tczajka/bigint-benchmark-rs
  • astro-float benchmark: https://github.com/stencillogic/bigfloat-bench
-- From 日报小组 RustPlumber
社区学习交流平台订阅:
  • Rust.cc 论坛: 支持 rss
  • 微信公众号:Rust 语言中文社区

原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2020-06-11

  • 博文量
    1769
  • 访问量
    718516