Databend 整合了一些性能分析工具,能够不便进行深入分析。本文将会介绍如何进行 CPU / Memory Profiling。CPU Profiling
CPU ProfilingCPU 剖析,依照肯定的频率采集所监听的应用程序 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=20Fetching profile over HTTP from http://localhost:8080/debug/pprof/profile?seconds=20Saved profile in ~/pprof/pprof.samples.cpu.001.pb.gzType: cpuTime: 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) topShowing nodes accounting for 141.41ms, 100% of 141.41ms totalShowing 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,后果如下所示:
...