Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for FlameGraphs on Steroids with profiler.firefox.com
YugabyteDB profile imageFranck Pachot
Franck Pachot forYugabyteDB

Posted on • Edited on

     

FlameGraphs on Steroids with profiler.firefox.com

Usingperf on Linux is a great way to understand your CPU consumption. It is mostly harmless on modern kernels, especially when running for a short time, but try it on a test environment first if you can.

Here is an example where I gather 99 samples per second, during 10 seconds, for PostgreSQL and YugabyteDB processes and threads:

ssh my.server'sudo bash -c "perf record -o - --call-graph fp -F99 -e cpu-cycles \ -p $(pgrep -d, postgres\|yb-tserver\|yb-master) sleep 10 | perf script -F +pid"'>$(date +%Y%m%d%H%M%S |tee /dev/stderr).perf
Enter fullscreen modeExit fullscreen mode

This generates a file that can be read by the Firefox Profiler.
Go tohttps://profiler.firefox.com/ and load the generated file.

You will get something that looks like this:
Image description

On the upper right, you can upload it to share it. I did this, which means that you can see mine here:https://share.firefox.dev/4576kKY

I gathered the perf statistics during 10 seconds while running this on YugabyteDB:

droptableifexistsdemo;createtabledemo(idbigint);insertintodemoselectgenerate_series(1,300000);\watch
Enter fullscreen modeExit fullscreen mode

Maybe you already see what's wrong here: I didn't define a primary key. But how does that impact my CPU usage?

I filter on thepostgres process:
Image description

In YugabyteDB, thepostgres process is running the query layer, with additional threads (likepggate to talk to the storage layer):

Image description

This shows the call tree I can navigate, similar toperf top orperf report, but with a graphical interface.

One interesting view is theStack Chart, which follows the timeline:
Image description

My query was not active during the whole 10 seconds of sampling. It has been running a few seconds and then\watch was waiting.

A view made popular by Brenda Gregg is theFlame Graph:
Image description

Here, for example, I see that I spend some time reading from a virtual filesystem. I focus on this part:

Image description

The names of the YugabyteDB functions give a clue. TheCall Tree shows the full names (right-click to copy it as text):
Image description

The stack gives a lot of information:

_extract_crngurandom_read_nowarn.isra.34urandom_read__vfs_readvfs_readksys_read__arm64_sys_readel0_svc_commonel0_svc_handlerel0_svc__readboost::uuids::detail::random_provider_base::get_random_bytesyb::GenerateObjectIdyb::pggate::PgApiImpl::TupleIdBuilder::BuildYBCPgBuildYBTupleIdYBCGetYBTupleIdFromTuple
Enter fullscreen modeExit fullscreen mode

Of course, I can guess from the function names, butYugabyteDB is open-source, and I can search for them. What happens here is that I didn't declare a Primary Key for my table, and then an internal one (ybctid) is generated because secondary indexes need a key to address the table row. This ID generation calls/dev/urandom. I made this simple example to show that low-level traces can give a clue about high-level data model problems.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
_04f28174ad6362cc84e82 profile image
刘国华
  • Joined

Great article, thank you for sharing!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Open Source Distributed PostgreSQL

Join the Yugabyte Cloud today, and start using a distributed, PostgreSQL-compatible, DBaaS.

More fromYugabyteDB

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp