< 返回版块

Folyd 发表于 2020-12-12 16:01

dhat - 监控你的Rust程序堆内存使用情况的crate

dhat是《Rust性能之书》作者新发布的crate,帮助大家只用几行代码就可以监控rust程序的堆内存使用情况。

它提供了两种监控方式:

  • heap profiling
use dhat::{Dhat, DhatAlloc};

// 使用dhat提供的DhatAlloc
#[global_allocator]
static ALLOCATOR: DhatAlloc = DhatAlloc;

fn main() {
    // 在main函数最开头调用这个方法
    let _dhat = Dhat::start_heap_profiling();
}
  • ad hoc profiling
use dhat::Dhat;

fn main() {
    let _dhat = Dhat::start_ad_hoc_profiling();

}
    dhat::ad_hoc_event(100);

运行之后分别会生成dhat-heap.json 或 dhat-ad-hoc.json两个json文件,需要使用Valgrind来查看。

链接:https://docs.rs/dhat/0.2.0/dhat/

Measuring Memory Usage in Rust

rust-analyzer的作者写了一篇文章讲了如何监控Rust程序内存使用情况的几种方法。

链接:https://rust-analyzer.github.io/blog/2020/12/04/measuring-memory-usage-in-rust.html

DeisLabs 使用 Rust 一年后总结:Still Rusting

微软Azure的 DeisLabs 团队在去年使用 Rust 开发了 Krustlet 概念验证型项目,基于 wasmtime 实现的 wasm-wasi 版的 Kubelet,实现了在K8S中运行 wasm 负载。

一年后该团队写这篇文章,总结了 Rust 的Good、Bad和Ugly 三方面。

Good:

  • traits: 帮助你设计可扩展的API
  • 第三方库 serde:超优秀
  • 错误处理、Option 和 迭代器
  • Enum的表现力和便利性
  • Cargo
  • 强制性的 Unsafe 标记不安全的边界

Bad:

  • 生态系统中crate的文档,虽然指明了功能使用方法,但不够清晰,还必须查看源码才能发现是否真的是零成本抽象,或者有没有副作用。库作者在文档上还需要多花点心思。
  • 生态系统中很多crate 功能并不完善。
  • 操作实现同一个trait的集合类型有点烦人,比如这篇文章里的例子:https://deislabs.io/posts/a-fistful-of-states/
  • 发现Rust 学习曲线有两种:上手 Rust 、 设计合适的 API (特别是使用泛型和trait的时候)
  • 宏有时候会导致奇怪或难以解释的错误,编译器标记发生错误的地方和实际发生错误的地方并不一致
  • 有些trait可能被使用过度(个人偏好)
  • Cargo.toml 中 dependency features可以配置的更具体更易于调试

Ugly:

  • 异步 (async/await)

该团队对Rust异步不满意的地方在于:

  • 异步运行时生态有竞争性问题(async-std、tokio等)
  • 到处都是复杂的不透明的返回类型,比如impl Future<Item = ...>
  • async trait 有持续的需求,但是没有内置到语言中
  • 为手动实现诸如AsyncRead之类编写的大量样板代码

认为Rust异步目前对于新手不是很友好,在开发体验上还有更大的改进空间。

总结:

Rust 提升了工作乐趣,强烈推荐将 Rust 用于云原生应用。

附录:

DeisLabs 团队 对 Go 的看法:

「对于需要快速,轻松编写的小型项目,Go是一个很好的工具,但是由于大型项目的维护难度,我们通常避免使用它。 在因err!= nil而导致的膨胀,缺少集合功能(如映射和过滤),缺少泛型以及低于标准的依赖管理解决方案之间,随着项目规模的增加,维护变得越来越困难。」

链接:https://deislabs.io/posts/still-rusting-one-year-later/

OOXML - Rust 实现的 Office OpenXML 解析器

国内Rust开发者实现的,完成度为初步,大家可以关注下

目标:使用 Rust 有效地读取和编写OOXML组件。但是目前只支持xlsx解析。

链接:https://github.com/zitsen/ooxml-rs

《Rust Servers, Services, and Apps》- Manning新出的关于Rust web开发方面的书

Manning新出了一本Rust书,最近在MEAP阶段,原价$47.99,现折扣价$23.99。感兴趣的朋友可以关注一下。

简介:

Rust Servers, Services, and Apps is a hands-on guide to developing modern distributed web applications with Rust. You’ll learn how to build efficient services, write custom web servers, and even build full-stack applications end-to-end in Rust.

链接:https://www.manning.com/books/rust-servers-services-and-apps

嵌入式中的Rust async体验

链接:https://blog.drogue.io/rust-and-async/

-- From 日报小组 Folyd

社区学习交流平台订阅:

评论区

写评论

还没有评论

1 共 0 条评论, 1 页