关于性能测试:Databend-性能剖析方法与工具

5次阅读

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

Databend 整合了一些性能分析工具,能够不便进行深入分析。本文将会介绍如何进行 CPU / Memory Profiling。CPU Profiling

CPU Profiling

CPU 剖析,依照肯定的频率采集所监听的应用程序 CPU(含寄存器)的应用状况,可确定应用程序在被动耗费 CPU 周期时破费工夫的地位。

pprof 是 Google 开源的代码性能剖析工具,能够间接生成代码剖析报告,不仅反对通过命令式交互查看,也便于可视化展现。Databend 应用 pprof-rs1 实现对 pprof 工具的反对。

必备工作

CPU 剖析属于 Databend 的内置能力,部署一个 Databend 实例即可开始应用。

命令行交互

go tool pprof http://localhost:<your-databend-port>/debug/pprof/profile?seconds=<your-profile-second>

若 http 端口为 8080,采样工夫为 20 秒,后果示例如下:

$ go tool pprof http://localhost:8080/debug/pprof/profile?seconds=20
Fetching profile over HTTP from http://localhost:8080/debug/pprof/profile?seconds=20
Saved profile in ~/pprof/pprof.samples.cpu.001.pb.gz
Type: cpu
Time: Jul 15, 2022 at 9:45am (CST)
Duration: 20s, Total samples = 141.41ms (0.71%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 141.41ms, 100% of 141.41ms total
Showing top 10 nodes out of 218
      flat  flat%   sum%        cum   cum%
  141.41ms   100%   100%   141.41ms   100%  backtrace::backtrace::libunwind::trace
         0     0%   100%    10.10ms  7.14%  <&mut regex_syntax::utf8::Utf8Sequences as core::iter::traits::iterator::Iterator>::next
         0     0%   100%    10.10ms  7.14%  <<std::thread::Builder>::spawn_unchecked_<sled::threadpool::queue::spawn_to<sled::pagecache::iterator::scan_segment_headers_and_tail::{closure#0}::{closure#0}, core::option::Option<(u64, sled::pagecache::logger::SegmentHeader)>>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         0     0%   100%    10.10ms  7.14%  <<std::thread::Builder>::spawn_unchecked_<sled::threadpool::queue::spawn_to<sled::pagecache::iterator::scan_segment_headers_and_tail::{closure#0}::{closure#0}, core::option::Option<(u64, sled::pagecache::logger::SegmentHeader)>>::{closure#0}::{closure#1}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         0     0%   100%    10.10ms  7.14%  <<std::thread::Builder>::spawn_unchecked_<sled::threadpool::queue::spawn_to<sled::pagecache::iterator::scan_segment_headers_and_tail::{closure#0}::{closure#0}, core::option::Option<(u64, sled::pagecache::logger::SegmentHeader)>>::{closure#0}::{closure#2}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         0     0%   100%    10.10ms  7.14%  <<std::thread::Builder>::spawn_unchecked_<sled::threadpool::queue::spawn_to<sled::pagecache::iterator::scan_segment_headers_and_tail::{closure#0}::{closure#0}, core::option::Option<(u64, sled::pagecache::logger::SegmentHeader)>>::{closure#0}::{closure#3}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         0     0%   100%    10.10ms  7.14%  <[&str]>::iter
         0     0%   100%    10.10ms  7.14%  <[(char, &[char])]>::binary_search_by::<<[(char, &[char])]>::binary_search_by_key<char, regex_syntax::unicode::simple_fold::imp::{closure#0}>::{closure#0}>
         0     0%   100%    10.10ms  7.14%  <[(char, &[char])]>::binary_search_by_key::<char, regex_syntax::unicode::simple_fold::imp::{closure#0}>
         0     0%   100%    10.10ms  7.14%  <[(char, &[char])]>::binary_search_by_key::<char, regex_syntax::unicode::simple_fold::imp::{closure#0}>::{closure#0}

可视化

执行下述命令能够进行可视化:

go tool pprof -http=0.0.0.0:<your-profile-port> <your profile data>

例如,执行下述语句能够在 8088 端口开启 WEB UI。

go tool pprof -http=0.0.0.0:8088 ~/pprof/pprof.samples.cpu.001.pb.gz 

拜访 http://0.0.0.0:8088/ui/flameg… 即可失去火焰图。

注意事项

Databend 临时不反对在 musl 平台上运行 pprof。

Memory Profiling

内存剖析,在应用程序进行堆调配时记录堆栈追踪,用于监督以后和历史内存应用状况,以及查看内存透露。通过与 jemalloc 的集成,Databend 得以整合多种内存剖析能力。这里应用 jeprof 进行内存剖析。

必备工作

  • 装置 Jemalloc,并启用其分析能力 ./configure –enable-prof
  • 在构建二进制文件时启用 memory-profiling 个性:cargo build –features memory-profiling
  • 在创立 Databend 实例时,设置环境变量 MALLOC_CONF=prof:true 以启用内存剖析。示例:

    MALLOC_CONF=prof:true ./target/debug/databend-query

堆快照转储

jeprof <your-profile-target> http://localhost:<your-databend-port>/debug/mem

上面的例子选用 debug 模式下编译的 databend-query 作为 target,端口为 8080,后果如下所示:

$ jeprof ./target/debug/databend-query http://localhost:8080/debug/mem
Using local file ./target/debug/databend-query.
Gathering CPU profile from http://localhost:8080/debug/mem/pprof/profile?seconds=30 for 30 seconds to
  ~/jeprof/databend-query.1658367127.localhost
Be patient...
Wrote profile to ~/jeprof/databend-query.1658367127.localhost
Welcome to jeprof!  For help, type 'help'.
(jeprof) top
Total: 11.1 MB
     6.0  54.6%  54.6%      6.0  54.6% ::alloc_zeroed
     5.0  45.4% 100.0%      5.0  45.4% ::alloc
     0.0   0.0% 100.0%      0.5   4.5% ::add_node::{closure#0}
     0.0   0.0% 100.0%      5.0  45.4% ::alloc_impl
     0.0   0.0% 100.0%      5.0  45.4% ::allocate
     0.0   0.0% 100.0%      4.5  40.8% ::allocate_in
     0.0   0.0% 100.0%      0.5   4.5% ::apply_batch_inner
     0.0   0.0% 100.0%     11.1 100.0% ::block_on::
     0.0   0.0% 100.0%     11.1 100.0% ::block_on::::{closure#0}
     0.0   0.0% 100.0%      0.5   4.5% ::clone
(jeprof) 

生成内存调配调用图

常见的用例之一是查找内存透露,通过比拟距离前后的内存画像即可实现这一工作。在上面的命令行中,以 10 s 为距离,获取前后两个工夫节点的内存画像。

curl 'http://localhost:<your-databend-port>/debug/mem/pprof/profile?seconds=0' > a.prof
sleep 10
curl 'http://localhost:<your-databend-port>/debug/mem/pprof/profile?seconds=0' > b.prof

接着,能够利用这两份内存画像来生成 pdf 格局的内存调配调用图。

jeprof \
    --show_bytes \
    --nodecount=1024 \
    --nodefraction=0.001 \
    --edgefraction=0.001 \
    --maxdegree=64 \
    --pdf \
    <your-profile-target> \
    --base=a.prof \
    b.prof \
    > mem.pdf

同样选用 debug 模式下编译的 databend-query 作为 target,端口为 8080,后果如图所示:

注意事项

目前无奈在 Mac 上进行内存剖析,不论是 x86_64 还是 aarch64 平台。

对于 Databend

Databend 是一款开源、弹性、低成本,基于对象存储也能够做实时剖析的旧式数仓。期待您的关注,一起摸索云原生数仓解决方案,打造新一代开源 Data Cloud。

  • Databend 文档:https://databend.rs/
  • Twitter:https://twitter.com/Datafuse_…
  • Slack:https://datafusecloud.slack.com/
  • Wechat:Databend
  • GitHub:https://github.com/datafusela…

文章首发于公众号:Databend


  1. https://crates.io/crates/pprof ↩
正文完
 0