hyper v1+anyhow 可能导致性能急速下降

23次阅读

共计 524 个字符,预计需要花费 2 分钟才能阅读完成。

出问题的源码

https://gist.github.com/lsk569937453/b42a8cfce21bd20c5da8737db1f5a1b1

导致的问题

加了 anyhow = {version = “1.0.xx”} 之后,gateway 的 TPS 从 8w 降到 4w(4 核 8G 的 docker 容器)。

怎么修复

anyhow = {version = “1.0.xx”, default-features = false}

怎么避免

  • 项目依赖的 crates 中的 anyhow 必须是非 std 的即 anyhow = {version = “1.0.xx”, default-features = false}
  • 项目依赖的 crates 中,如果依赖了 anyhow,也必须是非 std 得。否则,项目会出现性能下降。比如项目依赖了 log4rs 和 https://github.com/BinChengZhao/delay-timer, 由于这两个 crates 依赖了 std 的 anyhow,因此需要将 log4rs 和 delay-timer 排除掉,否则也会出问题。

问题原因

目前不确定是 anyhow 的问题还是 hyper v1 的问题。我用同样的代码在 hyper v0.14.xx 实现了一遍,没有发现问题。所以倾向是 hyper v1 的问题。

正文完
 0