SlideShare une entreprise Scribd logo
1  sur  61
Télécharger pour lire hors ligne
Performance Analysis
The Rust edition
Performance Analysis
Questions:
Performance Analysis
Questions:
Who ate my CPU?
Performance Analysis
Questions:
Who ate my CPU? Who ate my RAM?
CPU
CPU profiling
$ cargo install flamegraph
$ cargo flamegraph --dev
CPU profiling
$ cargo install flamegraph
$ cargo flamegraph --dev
dtrace: system integrity protection is on, some features will not be
available
dtrace: failed to initialize dtrace: DTrace requires additional
privileges
failed to sample program
Just use linux
$ docker run --rm rust:1.51
# apt-get install linux-perf
...
# cargo flamegraph
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
/usr/bin/perf: line 13: exec: perf_5.10: not found
E: linux-perf-5.10 is not installed.
failed to sample program
Match the kernel version
$ docker run --rm rust:1.51-bullseye
# apt-get install linux-perf
...
# cargo flamegraph --dev
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
….
Profiling a running program
$ cargo install inferno
$ perf record -p "$(pgrep profexample)" -F 997 -g
…^C
[ perf record: Captured and wrote 5.535 MB perf.data (81144 samples) ]
$ perf script | inferno-collapse-perf > stacks.folded
$ inferno-flamegraph < stacks.folded > flamegraph.svg
$ open flamegraph.svg
...
Small digression
● Frame pointers:
push rbp
mov rbp, rsp
Small digression (2)
● On x86-64 the default is to omit frame pointers
● X86-64 ABI says:
● The conventional use of %rbp as a frame pointer for the stack frame may be avoided by using %rsp (the stack
pointer) to index into the stack frame. This technique saves two instructions in the prologue and epilogue and
makes one additional general-purpose register (%rbp) available.
● Gcc since 4.6 omits frame pointers by default on x84-6
● Rust omits frame pointers also on dev builds
● DWARF info is used to figure out the layout of the stack frame for
each function. You don’t need full debug info for backtraces:
[profile.release]
debug = 1
Profiling a running program
$ cargo install inferno
$ perf record -p "$(pgrep profexample)" -F 997 -g --call-graph dwarf
…^C
[ perf record: Captured and wrote 461.199 MB perf.data (57251 samples) ]
$ perf script | inferno-collapse-perf > stacks.folded
$ inferno-flamegraph < stacks.folded > flamegraph.svg
$ open flamegraph.svg
...
Questions:
What are those unknown functions called by “factorial”?
Questions:
● What if I want to run this on k8s where I don’t control my kernel version?
● What if I want to run this on mac without pulling my hair out?
● What if I don’t have a shell on prod?
Questions:
● What if I want to run this on k8s where I don’t control my kernel version?
● What if I want to run this on mac without pulling my hair out?
● What if I don’t have a shell on prod?
Go
package main
import (
"net/http"
_ "net/http/pprof"
)
func main() {
// ...
http.ListenAndServe("localhost:6060", nil)
}
$ go tool pprof --http localhost:4080
'http://localhost:6060/debug/pprof/profile'
Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile
Saved profile in /Users/mkm/pprof/pprof.samples.cpu.001.pb.gz
Serving web UI on http://localhost:4080
● https://github.com/google/pprof
○ Multiple languages, not only Go
● https://github.com/google/perf_data_converter
Rust?
Enter: tikv/pprof-rs !!
[dependencies]
+pprof = { version = "0.4", features = ["flamegraph"] }
tikv/pprof-rs
fn main() {
+ let guard = pprof::ProfilerGuard::new(997).unwrap();
+
for _ in 0..6 {
thread::spawn(worker);
}
thread::sleep(time::Duration::from_secs(10));
+
+ if let Ok(report) = guard.report().build() {
+ let file = File::create("flamegraph.svg").unwrap();
+ report.flamegraph(file).unwrap();
+ };
}
$ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080
$ firefox 'http://localhost:8080/debug/pprof/profile?seconds=30'
$ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080
$ go tool --http localhost:4080 
pprof 'http://localhost:8080/debug/pprof/profile?seconds=30'
Compatible with https://speedscope.app
How does that work
https://github.com/influxdata/influxdb_iox/blob/main/src/influxdb_ioxd/http.rs#L364
How does that work
$ curl 'http://localhost:8080/debug/pprof/profile?seconds=1' | pq --msgtype perftools.profiles.Profile | jq
{
"sample_type": [
{
"type": 1164,
"unit": 1165
}
],
"sample": [
{
"location_id": [
1,
2,
...
"value": [
1
],
...
"string_table": [
"",
"flatbuffers::builder::FlatBufferBuilder::create_string",
"_ZN81_$LT$core..str..iter..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17hfd848827f3ee829eE",
"_ZN4core3ptr19swap_nonoverlapping17h364e10b3426efe72E",
"_ZN6server15Server$LT$M$GT$19write_sharded_entry28_$u7b$$u7b$closure$u7d$$u7d$17h4746f0c3132c7a41E",
"_ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17h20a22a0cdaab7f27E",
"_ZN22influxdb_line_protocol7tag_key17hf795357f1c28005dE",
How does that work
$ curl -s -H "accept: text/html" 'http://localhost:8080/debug/pprof/profile?seconds=1' | head
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" width="1200" height="2262" onload="init(evt)" viewBox="0 0
1200 2262" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:fg="http://github.com/jonhoo/inferno"><!--Flame graph stack visualization. See https://github.com/brendangregg/FlameGraph for
latest version, and http://www.brendangregg.com/flamegraphs.html for examples.--><!--NOTES: --><defs><linearGradient id="background"
y1="0" y2="1" x1="0" x2="0"><stop stop-color="#eeeeee" offset="5%"/><stop stop-color="#eeeeb0"
offset="95%"/></linearGradient></defs><style type="text/css">
text { font-family:"Verdana"; font-size:12px; fill:rgb(0,0,0); }
#title { text-anchor:middle; font-size:17px; }
#search { opacity:0.1; cursor:pointer; }
#search:hover, #search.show { opacity:1; }
#subtitle { text-anchor:middle; font-color:rgb(160,160,160); }
#unzoom { cursor:pointer; }
#frames > *:hover { stroke:black; stroke-width:0.5; cursor:pointer; }
.hide { display:none; }
.parent { opacity:0.5; }
...
Backtraces and async
https://github.com/rust-lang/rust/issues/73524
HEAP
Attempt 1
[dependencies]
tikv-jemallocator = {version = "0.4.0", features = ["profiling"] }
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
$ cargo build &&
_RJEM_MALLOC_CONF="prof:true,prof_final:true,prof_prefix:jeprof.out"
./target/debug/profexample
Attempt 2: implement it like pprof-rs
use super::Profiler;
use libc::{c_int, c_void, size_t};
#[link(name = "jemalloc")]
extern "C" {
#[link_name = "_rjem_malloc"]
pub fn sys_malloc(size: size_t) -> *mut c_void;
#[link_name = "_rjem_free"]
pub fn sys_free(ptr: *mut c_void);
#[link_name = "_rjem_realloc"]
pub fn sys_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
}
#[no_mangle]
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
Profiler::track_allocated(size as isize);
sys_malloc(size)
}
//! The standard API includes: the [`malloc`], [`calloc`], [`realloc`], and
//! [`free`], which conform to to ISO/IEC 9899:1990 (“ISO C90”),
//! [`posix_memalign`] which conforms to conforms to POSIX.1-2016, and
//! [`aligned_alloc`].
Questions
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust

Contenu connexe

Tendances

Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
SANG WON PARK
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
Brendan Gregg
 
Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips
confluent
 

Tendances (20)

Diving into the Deep End - Kafka Connect
Diving into the Deep End - Kafka ConnectDiving into the Deep End - Kafka Connect
Diving into the Deep End - Kafka Connect
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
PostgreSQLのトラブルシューティング@第5回中国地方DB勉強会
PostgreSQLのトラブルシューティング@第5回中国地方DB勉強会PostgreSQLのトラブルシューティング@第5回中国地方DB勉強会
PostgreSQLのトラブルシューティング@第5回中国地方DB勉強会
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
 
行ロックと「LOG: process 12345 still waiting for ShareLock on transaction 710 afte...
行ロックと「LOG:  process 12345 still waiting for ShareLock on transaction 710 afte...行ロックと「LOG:  process 12345 still waiting for ShareLock on transaction 710 afte...
行ロックと「LOG: process 12345 still waiting for ShareLock on transaction 710 afte...
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21
 
Apache Bigtopによるオープンなビッグデータ処理基盤の構築(オープンデベロッパーズカンファレンス 2021 Online 発表資料)
Apache Bigtopによるオープンなビッグデータ処理基盤の構築(オープンデベロッパーズカンファレンス 2021 Online 発表資料)Apache Bigtopによるオープンなビッグデータ処理基盤の構築(オープンデベロッパーズカンファレンス 2021 Online 発表資料)
Apache Bigtopによるオープンなビッグデータ処理基盤の構築(オープンデベロッパーズカンファレンス 2021 Online 発表資料)
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
The Columnar Era: Leveraging Parquet, Arrow and Kudu for High-Performance Ana...
The Columnar Era: Leveraging Parquet, Arrow and Kudu for High-Performance Ana...The Columnar Era: Leveraging Parquet, Arrow and Kudu for High-Performance Ana...
The Columnar Era: Leveraging Parquet, Arrow and Kudu for High-Performance Ana...
 
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
Multi cluster, multitenant and hierarchical kafka messaging service   slideshareMulti cluster, multitenant and hierarchical kafka messaging service   slideshare
Multi cluster, multitenant and hierarchical kafka messaging service slideshare
 
Apache Kafkaって本当に大丈夫?~故障検証のオーバービューと興味深い挙動の紹介~
Apache Kafkaって本当に大丈夫?~故障検証のオーバービューと興味深い挙動の紹介~Apache Kafkaって本当に大丈夫?~故障検証のオーバービューと興味深い挙動の紹介~
Apache Kafkaって本当に大丈夫?~故障検証のオーバービューと興味深い挙動の紹介~
 
eBPF/XDP
eBPF/XDP eBPF/XDP
eBPF/XDP
 
Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips
 
Apache kafka performance(latency)_benchmark_v0.3
Apache kafka performance(latency)_benchmark_v0.3Apache kafka performance(latency)_benchmark_v0.3
Apache kafka performance(latency)_benchmark_v0.3
 
ksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database SystemksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database System
 
Docker Networking Deep Dive
Docker Networking Deep DiveDocker Networking Deep Dive
Docker Networking Deep Dive
 
2021 10-13 i ox query processing
2021 10-13 i ox query processing2021 10-13 i ox query processing
2021 10-13 i ox query processing
 
Scaling Apache Spark at Facebook
Scaling Apache Spark at FacebookScaling Apache Spark at Facebook
Scaling Apache Spark at Facebook
 
PostgreSQLではじめるOSS開発@OSC 2014 Hiroshima
PostgreSQLではじめるOSS開発@OSC 2014 HiroshimaPostgreSQLではじめるOSS開発@OSC 2014 Hiroshima
PostgreSQLではじめるOSS開発@OSC 2014 Hiroshima
 
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
 

Similaire à Performance Profiling in Rust

Systemtap
SystemtapSystemtap
Systemtap
Feng Yu
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
ronnywang_tw
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
Logicaltrust pl
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
Yury Chemerkin
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
Deployment with Fabric
Deployment with FabricDeployment with Fabric
Deployment with Fabric
andymccurdy
 

Similaire à Performance Profiling in Rust (20)

Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Systemtap
SystemtapSystemtap
Systemtap
 
Deep learning - the conf br 2018
Deep learning - the conf br 2018Deep learning - the conf br 2018
Deep learning - the conf br 2018
 
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Containers for sysadmins
Containers for sysadminsContainers for sysadmins
Containers for sysadmins
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Deployment with Fabric
Deployment with FabricDeployment with Fabric
Deployment with Fabric
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Nodejs Performance Debug
Nodejs Performance DebugNodejs Performance Debug
Nodejs Performance Debug
 
Red Hat OpenStack 17 저자직강+스터디그룹_4주차
Red Hat OpenStack 17 저자직강+스터디그룹_4주차Red Hat OpenStack 17 저자직강+스터디그룹_4주차
Red Hat OpenStack 17 저자직강+스터디그룹_4주차
 
Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36
 

Plus de InfluxData

How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
InfluxData
 
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...How Delft University's Engineering Students Make Their EV Formula-Style Race ...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
InfluxData
 
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
InfluxData
 
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
InfluxData
 

Plus de InfluxData (20)

Announcing InfluxDB Clustered
Announcing InfluxDB ClusteredAnnouncing InfluxDB Clustered
Announcing InfluxDB Clustered
 
Best Practices for Leveraging the Apache Arrow Ecosystem
Best Practices for Leveraging the Apache Arrow EcosystemBest Practices for Leveraging the Apache Arrow Ecosystem
Best Practices for Leveraging the Apache Arrow Ecosystem
 
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
 
Power Your Predictive Analytics with InfluxDB
Power Your Predictive Analytics with InfluxDBPower Your Predictive Analytics with InfluxDB
Power Your Predictive Analytics with InfluxDB
 
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
 
Build an Edge-to-Cloud Solution with the MING Stack
Build an Edge-to-Cloud Solution with the MING StackBuild an Edge-to-Cloud Solution with the MING Stack
Build an Edge-to-Cloud Solution with the MING Stack
 
Meet the Founders: An Open Discussion About Rewriting Using Rust
Meet the Founders: An Open Discussion About Rewriting Using RustMeet the Founders: An Open Discussion About Rewriting Using Rust
Meet the Founders: An Open Discussion About Rewriting Using Rust
 
Introducing InfluxDB Cloud Dedicated
Introducing InfluxDB Cloud DedicatedIntroducing InfluxDB Cloud Dedicated
Introducing InfluxDB Cloud Dedicated
 
Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB Gain Better Observability with OpenTelemetry and InfluxDB
Gain Better Observability with OpenTelemetry and InfluxDB
 
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
 
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...How Delft University's Engineering Students Make Their EV Formula-Style Race ...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
 
Introducing InfluxDB’s New Time Series Database Storage Engine
Introducing InfluxDB’s New Time Series Database Storage EngineIntroducing InfluxDB’s New Time Series Database Storage Engine
Introducing InfluxDB’s New Time Series Database Storage Engine
 
Start Automating InfluxDB Deployments at the Edge with balena
Start Automating InfluxDB Deployments at the Edge with balena Start Automating InfluxDB Deployments at the Edge with balena
Start Automating InfluxDB Deployments at the Edge with balena
 
Understanding InfluxDB’s New Storage Engine
Understanding InfluxDB’s New Storage EngineUnderstanding InfluxDB’s New Storage Engine
Understanding InfluxDB’s New Storage Engine
 
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDBStreamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
 
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
 
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
 
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
 
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
 
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Performance Profiling in Rust

  • 2.
  • 3.
  • 4.
  • 7. Performance Analysis Questions: Who ate my CPU? Who ate my RAM?
  • 8. CPU
  • 9.
  • 10. CPU profiling $ cargo install flamegraph $ cargo flamegraph --dev
  • 11. CPU profiling $ cargo install flamegraph $ cargo flamegraph --dev dtrace: system integrity protection is on, some features will not be available dtrace: failed to initialize dtrace: DTrace requires additional privileges failed to sample program
  • 12.
  • 13. Just use linux $ docker run --rm rust:1.51 # apt-get install linux-perf ... # cargo flamegraph Finished dev [unoptimized + debuginfo] target(s) in 0.03s /usr/bin/perf: line 13: exec: perf_5.10: not found E: linux-perf-5.10 is not installed. failed to sample program
  • 14.
  • 15. Match the kernel version $ docker run --rm rust:1.51-bullseye # apt-get install linux-perf ... # cargo flamegraph --dev Finished dev [unoptimized + debuginfo] target(s) in 0.03s ….
  • 16.
  • 17. Profiling a running program $ cargo install inferno $ perf record -p "$(pgrep profexample)" -F 997 -g …^C [ perf record: Captured and wrote 5.535 MB perf.data (81144 samples) ] $ perf script | inferno-collapse-perf > stacks.folded $ inferno-flamegraph < stacks.folded > flamegraph.svg $ open flamegraph.svg ...
  • 18.
  • 19. Small digression ● Frame pointers: push rbp mov rbp, rsp
  • 20. Small digression (2) ● On x86-64 the default is to omit frame pointers ● X86-64 ABI says: ● The conventional use of %rbp as a frame pointer for the stack frame may be avoided by using %rsp (the stack pointer) to index into the stack frame. This technique saves two instructions in the prologue and epilogue and makes one additional general-purpose register (%rbp) available. ● Gcc since 4.6 omits frame pointers by default on x84-6 ● Rust omits frame pointers also on dev builds ● DWARF info is used to figure out the layout of the stack frame for each function. You don’t need full debug info for backtraces: [profile.release] debug = 1
  • 21. Profiling a running program $ cargo install inferno $ perf record -p "$(pgrep profexample)" -F 997 -g --call-graph dwarf …^C [ perf record: Captured and wrote 461.199 MB perf.data (57251 samples) ] $ perf script | inferno-collapse-perf > stacks.folded $ inferno-flamegraph < stacks.folded > flamegraph.svg $ open flamegraph.svg ...
  • 22.
  • 23. Questions: What are those unknown functions called by “factorial”?
  • 24. Questions: ● What if I want to run this on k8s where I don’t control my kernel version? ● What if I want to run this on mac without pulling my hair out? ● What if I don’t have a shell on prod?
  • 25. Questions: ● What if I want to run this on k8s where I don’t control my kernel version? ● What if I want to run this on mac without pulling my hair out? ● What if I don’t have a shell on prod?
  • 26.
  • 27. Go package main import ( "net/http" _ "net/http/pprof" ) func main() { // ... http.ListenAndServe("localhost:6060", nil) }
  • 28. $ go tool pprof --http localhost:4080 'http://localhost:6060/debug/pprof/profile' Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile Saved profile in /Users/mkm/pprof/pprof.samples.cpu.001.pb.gz Serving web UI on http://localhost:4080
  • 29.
  • 30.
  • 31.
  • 32. ● https://github.com/google/pprof ○ Multiple languages, not only Go ● https://github.com/google/perf_data_converter
  • 33. Rust? Enter: tikv/pprof-rs !! [dependencies] +pprof = { version = "0.4", features = ["flamegraph"] }
  • 34. tikv/pprof-rs fn main() { + let guard = pprof::ProfilerGuard::new(997).unwrap(); + for _ in 0..6 { thread::spawn(worker); } thread::sleep(time::Duration::from_secs(10)); + + if let Ok(report) = guard.report().build() { + let file = File::create("flamegraph.svg").unwrap(); + report.flamegraph(file).unwrap(); + }; }
  • 35.
  • 36.
  • 37.
  • 38. $ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080 $ firefox 'http://localhost:8080/debug/pprof/profile?seconds=30'
  • 39.
  • 40. $ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080 $ go tool --http localhost:4080 pprof 'http://localhost:8080/debug/pprof/profile?seconds=30'
  • 41.
  • 42.
  • 43.
  • 45. How does that work https://github.com/influxdata/influxdb_iox/blob/main/src/influxdb_ioxd/http.rs#L364
  • 46. How does that work $ curl 'http://localhost:8080/debug/pprof/profile?seconds=1' | pq --msgtype perftools.profiles.Profile | jq { "sample_type": [ { "type": 1164, "unit": 1165 } ], "sample": [ { "location_id": [ 1, 2, ... "value": [ 1 ], ... "string_table": [ "", "flatbuffers::builder::FlatBufferBuilder::create_string", "_ZN81_$LT$core..str..iter..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17hfd848827f3ee829eE", "_ZN4core3ptr19swap_nonoverlapping17h364e10b3426efe72E", "_ZN6server15Server$LT$M$GT$19write_sharded_entry28_$u7b$$u7b$closure$u7d$$u7d$17h4746f0c3132c7a41E", "_ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17h20a22a0cdaab7f27E", "_ZN22influxdb_line_protocol7tag_key17hf795357f1c28005dE",
  • 47. How does that work $ curl -s -H "accept: text/html" 'http://localhost:8080/debug/pprof/profile?seconds=1' | head <?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" width="1200" height="2262" onload="init(evt)" viewBox="0 0 1200 2262" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fg="http://github.com/jonhoo/inferno"><!--Flame graph stack visualization. See https://github.com/brendangregg/FlameGraph for latest version, and http://www.brendangregg.com/flamegraphs.html for examples.--><!--NOTES: --><defs><linearGradient id="background" y1="0" y2="1" x1="0" x2="0"><stop stop-color="#eeeeee" offset="5%"/><stop stop-color="#eeeeb0" offset="95%"/></linearGradient></defs><style type="text/css"> text { font-family:"Verdana"; font-size:12px; fill:rgb(0,0,0); } #title { text-anchor:middle; font-size:17px; } #search { opacity:0.1; cursor:pointer; } #search:hover, #search.show { opacity:1; } #subtitle { text-anchor:middle; font-color:rgb(160,160,160); } #unzoom { cursor:pointer; } #frames > *:hover { stroke:black; stroke-width:0.5; cursor:pointer; } .hide { display:none; } .parent { opacity:0.5; } ...
  • 49. HEAP
  • 50. Attempt 1 [dependencies] tikv-jemallocator = {version = "0.4.0", features = ["profiling"] } #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; $ cargo build && _RJEM_MALLOC_CONF="prof:true,prof_final:true,prof_prefix:jeprof.out" ./target/debug/profexample
  • 51.
  • 52. Attempt 2: implement it like pprof-rs use super::Profiler; use libc::{c_int, c_void, size_t}; #[link(name = "jemalloc")] extern "C" { #[link_name = "_rjem_malloc"] pub fn sys_malloc(size: size_t) -> *mut c_void; #[link_name = "_rjem_free"] pub fn sys_free(ptr: *mut c_void); #[link_name = "_rjem_realloc"] pub fn sys_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void; } #[no_mangle] pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void { Profiler::track_allocated(size as isize); sys_malloc(size) }
  • 53. //! The standard API includes: the [`malloc`], [`calloc`], [`realloc`], and //! [`free`], which conform to to ISO/IEC 9899:1990 (“ISO C90”), //! [`posix_memalign`] which conforms to conforms to POSIX.1-2016, and //! [`aligned_alloc`].
  • 54.
  • 55.
  • 56.