0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何使用OFF-CPU火焰圖調(diào)查分析Linux性能問題概述

Linux閱碼場 ? 來源:未知 ? 2018-12-23 13:47 ? 次閱讀

本文用off-cpu火焰圖分析一個程序的延遲(主要在拿鎖上),找出來瓶頸,并消除的故事。本文非常值得一讀,但是閱碼場沒有足夠的時間將其翻譯為中文,希望童鞋們直接讀英文。

The Setup

As a performance engineer at MemSQL, one of my primary responsibilities is to ensure that customer Proof of Concepts (POCs) run smoothly. I was recently asked to assist with a big POC, where I was surprised to encounter an uncommon Linux performance issue. I was running a synthetic workload of 16 threads (one for each CPU core). Each one simultaneously executed a very simple query (select count(*) from t where i > 5) against a columnstore table.

In theory, this ought to be a CPU bound operation since it would be reading from a file that was already in disk buffer cache. In practice, our cores were spending about 50% of their time idle

In this post, I’ll walk through some of the debugging techniques and reveal exactly how we reached resolution.

What were our threads doing?

After confirming that our workload was indeed using 16 threads, I looked at the state of our various threads. In every refresh of myhtopwindow, I saw that a handful of threads were in theDstate corresponding to “Uninterruptible sleep”:

Why were we going off CPU?

At this point, I generated anoff-cpu flamegraphusing Linuxperf_eventsto see why we entered this state.Off-CPUmeans that instead of looking at what is keeping the CPU busy, you look at what is preventing it from being busy by things happening elsewhere (e.g. waiting for IO or a lock). The normal way to generate these visualizations is to useperf inject -s, but the machine I tested on did not have a new enough version ofperf. Instead I had to use anawkscriptI had previously written:

$ sudoperfrecord --call-graph=fp -e 'sched:sched_switch' -e 'sched:sched_stat_sleep' -e 'sched:sched_stat_blocked' --pid $(pgrep memsqld | head -n 1) -- sleep 1

[ perf record: Woken up 1 times to write data ]

[ perf record: Captured and wrote 1.343 MB perf.data (~58684 samples) ]

$ sudoperfscript -f time,comm,pid,tid,event,ip,sym,dso,trace -i sched.data | ~/FlameGraph/stackcollapse-perf-sched.awk | ~/FlameGraph/flamegraph.pl --color=io --countname=us >off-cpu.svg

Note: recording scheduler events viaperf recordcan have a very large overhead and should be used cautiously in production environments. This is why I wrap theperf recordaround asleep 1to limit the duration.

In an off-cpu flamegraph, the width of a bar is proportional to the total time spent off cpu. Here we see a lot of time is spent inrwsem_down_write_failed.

From the repeated calls torwsem_down_read_failedandrwsem_down_write_failed, we see that culprit wasmmapcontending in the kernel on themm->mmap_semlock:

down_write(&mm->mmap_sem);

ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,&populate);

up_write(&mm->mmap_sem);

This was causing everymmapsyscall to take 10-20ms (almost half the latency of the query itself). MemSQL was so fast that that we had inadvertently written a benchmark for Linuxmmap!

The fix was simple — we switched from usingmmapto using the traditional filereadinterface. After this change, we nearly doubled our throughput and became CPU bound as we expected:

For more information and discussion around Linux performance,check out the original post on my personal blog.

Download MemSQL Community Edition to run your own performance tests for free today:memsql.com/download

Alex Reece is a systems and performance engineer. He believes in active benchmarking, root cause analysis, and fast code.

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • cpu
    cpu
    +關(guān)注

    關(guān)注

    68

    文章

    10776

    瀏覽量

    210462
  • Linux
    +關(guān)注

    關(guān)注

    87

    文章

    11177

    瀏覽量

    208490
  • SQL
    SQL
    +關(guān)注

    關(guān)注

    1

    文章

    751

    瀏覽量

    43989

原文標(biāo)題:用off-cpu火焰圖調(diào)查Linux性能問題

文章出處:【微信號:LinuxDev,微信公眾號:Linux閱碼場】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦

    Linux性能分析工具大全

    今天浩道跟大家分享關(guān)于linux性能分析過程中常用到的分析工具!
    發(fā)表于 01-05 09:52 ?588次閱讀

    中國鋰離子電池原材料市場調(diào)查分析報告2008-2009版

    中國鋰離子電池原材料市場調(diào)查分析報告2008-2009版 詳細(xì)內(nèi)容請見:http://www.boomingfield.com/Html/yjxxcl/2008-9/18
    發(fā)表于 12-29 15:12

    _首屆中國嵌入式應(yīng)用狀況_調(diào)查分析報告

    _首屆中國嵌入式應(yīng)用狀況_調(diào)查分析報告
    發(fā)表于 08-20 14:48

    火焰探測器參考方案

    和室外。而隨著技術(shù)的進(jìn)步,這樣的分界也逐漸模糊起來,比如今天我們拆解的這款由世健國際貿(mào)易(上海)有限公司設(shè)計的紅外火焰探測參考方案,就集快速、長距、高靈敏度等性能于一身,讓人刮目相看。1:世健紅外
    發(fā)表于 06-21 05:00

    全志Tina中使用perf分析CPU使用率

    perf簡介Perf是是內(nèi)置于Linux內(nèi)核源碼樹中的性能剖析(profiling)工具。不僅可以用于應(yīng)用程序的性能統(tǒng)計分析,還可以用于內(nèi)核的性能
    發(fā)表于 05-20 14:25

    火焰識別

    本人長期從事Linux系統(tǒng)的圖像處理產(chǎn)品研發(fā),近期在做火焰識別,火爐溫度控制,智能精準(zhǔn)滅火,最近在用樹莓派,期待本產(chǎn)品有更好的性能,我希望可以有機(jī)會試用該開發(fā)版,體驗新產(chǎn)品的強(qiáng)大功能,同時及時反饋自己的用戶體驗,使雙方共贏。
    發(fā)表于 07-23 10:18

    CPU核心工作性能

    CPU核心工作性能 CPU核心概述       
    發(fā)表于 12-17 10:59 ?331次閱讀

    Linux CPU性能應(yīng)該如何優(yōu)化

    Linux系統(tǒng)中,由于成本的限制,往往會存在資源上的不足,例如 CPU、內(nèi)存、網(wǎng)絡(luò)、IO 性能。本文,就對 Linux 進(jìn)程和 CPU
    的頭像 發(fā)表于 01-18 08:52 ?3305次閱讀

    疫情之下,中國LED顯示屏市場活力調(diào)查分析

    疫情之下,中國LED顯示屏市場活力調(diào)查分析 眾所周知市場活躍是行業(yè)發(fā)展的主要動力,而2020年初突如其來的疫情,給中國市場帶來了巨大的沖擊,LED顯示屏市場也不例外。而我們收到了行業(yè)多方面的市場反饋
    發(fā)表于 04-02 11:23 ?1897次閱讀

    火焰系列之使用火焰隱藏功能提高繪制精度

    我們可以看到,火焰顯示, func程序占用了近四分之一的CPU時間。但是由于我們把 func綁定在CPU0和1上執(zhí)行,根據(jù)小學(xué)數(shù)學(xué)我們應(yīng)該可以計算出來 func最多占用 2/32=6
    的頭像 發(fā)表于 06-23 10:15 ?1991次閱讀
    <b class='flag-5'>火焰</b><b class='flag-5'>圖</b>系列之使用<b class='flag-5'>火焰</b><b class='flag-5'>圖</b>隱藏功能提高繪制精度

    火焰:全局視野的Linux性能剖析

    CPU火焰圖中的每一個方框是一個函數(shù),方框的長度,代表了它的執(zhí)行時間,所以越寬的函數(shù),執(zhí)行越久。火焰的樓層每高一層,就是更深一級的函數(shù)被調(diào)用,最頂層的函數(shù),是葉子函數(shù)。
    的頭像 發(fā)表于 06-28 09:44 ?1998次閱讀

    殺手級分析——bootchart

    之前小弟一直在宣傳推廣火焰,結(jié)果是很多童鞋凡事都用火焰。說實話,火焰特別適合
    的頭像 發(fā)表于 09-08 09:13 ?7416次閱讀
    殺手級<b class='flag-5'>分析</b>——bootchart

    基于linux eBPF的進(jìn)程off-cpu的方法

    的swap等。如下圖所示,紅色部分屬于on-cpu部分,藍(lán)色部分屬于off-cpu。 一般我們用的perf命令等都是采樣on-cpu的指令進(jìn)行CPU的消耗
    的頭像 發(fā)表于 09-25 15:41 ?3044次閱讀
    基于<b class='flag-5'>linux</b> eBPF的進(jìn)程<b class='flag-5'>off-cpu</b>的方法

    Linux問題分析性能優(yōu)化

    文章來源于:https://mp.weixin.qq.com/s/d1NLXGp7teOgskussBXNMQ作者:alex目錄排查順序方法論性能分析工具CPU分析思路內(nèi)存
    的頭像 發(fā)表于 09-06 19:01 ?837次閱讀
    <b class='flag-5'>Linux</b>問題<b class='flag-5'>分析</b>與<b class='flag-5'>性能</b>優(yōu)化

    Linux問題故障定位的小技巧

    a. on-CPU:執(zhí)行中,執(zhí)行中的時間通常又分為用戶態(tài)時間user和系統(tǒng)態(tài)時間sys。 b. off-CPU:等待下一輪上CPU,或者等待I/O、鎖、換頁等等,其狀態(tài)可以細(xì)分為可執(zhí)行、匿名換頁、睡眠、鎖、空閑等狀態(tài)。
    的頭像 發(fā)表于 07-09 16:30 ?384次閱讀
    <b class='flag-5'>Linux</b>問題故障定位的小技巧