一个比较有趣的性能问题排查工具

greys是一个很强大的工具,简单的一句话就是强化版的btrace. 之前遇见一个问题,就是线上查询很慢,正好通过这个工具试着诊断一下。
一 安装greys
curl -sLk http://ompc.oss.aliyuncs.com/greys/install.sh|sh
cd greys
sh ./install-local.sh
二 诊断问题
jcmd 拿到 pid
root@hzxs-hadoop-pre-03:/data/src/greys # ./greys.sh 141930
                                                        _
  ____  ____ _____ _  _  ___ _____ _____ ____  _____ _| |_ ___  ____  _  _
/ _  |/ ___) ___ | | | |/___|_____|____ |  _ \(____ (_  _) _ \|    \| | | |
( (_| | |  | ____| |_| |___ |    / ___ | | | / ___ | | || |_| | | | | |_| |
\___ |_|  |_____)\__  (___/      \_____|_| |_\_____|  \__)___/|_|_|_|\__  |
(_____|          (____/                                              (____/
                                              +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                              |v|e|r|s|i|o|n|:|1|.|7|.|6|.|6|
                                              +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ga?>
查看问题:
ga?>trace com.bilibili.berserker.horoscope.biz.service.impl.HoroChannelDomainServiceImpl listChannelList
Affect(class-cnt:1 , method-cnt:1) cost in 416 ms.
`—+Tracing for : thread_name=”qtp2142442467-651″ thread_id=0x28b;is_daemon=false;priority=5;
    `—+[7371,7370ms]com.bilibili.berserker.horoscope.biz.service.impl.HoroChannelDomainServiceImpl:listChannelList()
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@38)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getPlatform(@39)
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@39)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getStartDate(@40)
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@40)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getEndDate(@41)
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@41)
        +—[9,8ms]com.bilibili.agilawood.util.BeanUtils:copy(@43)
        +—[9,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getStartDate(@46)
        +—[9,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getEndDate(@47)
        +—[9,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getSortField(@48)
        +—[9,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getSortType(@49)
        +—[7371,7362ms]com.bilibili.berserker.horoscope.dao.HoroChannelDataDAO:listChannels(@45)
        +—[7371,0ms]org.apache.commons.collections.CollectionUtils:isEmpty(@51)
        `—[7371,0ms]com.bilibili.agilawood.util.BeanUtils:copyList(@55)
发现大量的耗时在一个DAO操作上
原因是上线时候没有给查询条件加上索引导致的,添加索引后。
ga?>trace com.bilibili.berserker.horoscope.biz.service.impl.HoroChannelDomainServiceImpl listChannelList
Press Ctrl+D to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 474 ms.
`—+Tracing for : thread_name=”qtp685399117-2763″ thread_id=0xacb;is_daemon=false;priority=5;
    `—+[64,63ms]com.bilibili.berserker.horoscope.biz.service.impl.HoroChannelDomainServiceImpl:listChannelList()
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@38)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getPlatform(@39)
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@39)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getStartDate(@40)
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@40)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getEndDate(@41)
        +—[1,0ms]com.google.common.base.Preconditions:checkNotNull(@41)
        +—[1,0ms]com.bilibili.agilawood.util.BeanUtils:copy(@43)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getStartDate(@46)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getEndDate(@47)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getSortField(@48)
        +—[1,0ms]com.bilibili.berserker.horoscope.api.query.HoroChannelSimpleQuery:getSortType(@49)
        +—[64,63ms]com.bilibili.berserker.horoscope.dao.HoroChannelDataDAO:listChannels(@45)
        +—[64,0ms]org.apache.commons.collections.CollectionUtils:isEmpty(@51)
        `—[64,0ms]com.bilibili.agilawood.util.BeanUtils:copyList(@55)
一个SQL查询从7秒多降到了64毫秒。
三 总结
greys是一个不错的工具,还有其他很强大的功能,具体可见使用文档:https://yq.aliyun.com/articles/2390

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>