ARTHAS

最近压测通过arthas追踪  这是一个可以分析每个方法执行时间的好用的工具

一.trace

1.在线下载arthas

wget https://alibaba.github.io/arthas/arthas-boot.jar

2.启动

java -jar arthas-boot.jar

3.找进程号

4.trace追踪

trace com.wish.biz.pf.TemplateManageHelper executeBuildCheck

trace 类名全路径  方法名

追踪日志

注:如果有日志上看不到的时间,如图,有300ms的时间没有显示到日志上,就是进入到拦截器了

二.时空隧道

1.tt -t监控某个方法执行了几次

2. tt -i 获得某一次执行的详细信息  

如tt -i 1000   这里的1000就是tt -t监控出来的id

3.tt -i id -p重复执行

 

4.可以打开两个窗口,一边tt -i id -p 一边trace 

如图是上边-p是我同时trace的结果

三.arthas用户文档

https://www.bookstack.cn/read/arthas306/15.md
https://www.bookstack.cn/read/arthas306/27.md  用户文档

四.getstatic

通过getstatic命令可以方便的查看类的静态属性。使用方法为getstatic class_name field_name

获得到spring的ApplicationContext 然后为所欲为

cache是executeTempalatePool中的一个map型结构的类变量
getstatic com.wish.plat.spring.ApplicationContextHelper appCtx 'getBean("executeTempalatePool").cache.asMap().toString()'
getstatic com.wish.plat.spring.ApplicationContextHelper appCtx 'getBean("executeTempalatePool").cache.get("lncpmb0001")'

invalidate是cache的一个方法,是删除guava缓存
getstatic com.wish.plat.spring.ApplicationContextHelper appCtx 'getBean("executeTempalatePool").cache.invalidate("lncpmb0001")'

executeTempalatePool类

@Component
@Slf4j
public class ExecuteTempalatePool {
    private final LoadingCache<String, TemplateCacheEntity> cache;
    private final CacheUtil cacheUtil;

    /**
     * redis删除缓存时 guava缓存也删除
     * @param key
     */
    public void delGuavaCache(String key){
        this.cache.invalidate(key);
        log.info("监听删除,模板编码为:{},时间戳:{}",key,new Date());
    }

    @Autowired
    public ExecuteTempalatePool(CacheUtil cacheUtil){
        this.cacheUtil = cacheUtil;
        this.cache = CacheBuilder.newBuilder()
                //设置缓存池的大小,当缓存项超过该值时,则释放掉原有的链接
                .maximumSize(100)
                //设置对象没有进行读写超过5分钟则进行释放
                .expireAfterAccess(5, TimeUnit.MINUTES)
                .removalListener((RemovalListener<String, TemplateCacheEntity>) removalNotification -> {
                    log.debug("removed:{}",removalNotification.getKey());
                })
                .recordStats()
                .build(new CacheLoader<String, TemplateCacheEntity>() {
                    @Override
                    public TemplateCacheEntity load(String templateCode) {
                        log.info("load:{}",templateCode);
                        return cacheUtil.cacheTempalateExecute(templateCode);
                    }
                });
    }

    public TemplateCacheEntity getTemplateCacheEntity(String templateCode) {
        try {
            return this.cache.get(templateCode);
        } catch (ExecutionException e) {
            return this.cacheUtil.cacheTempalateExecute(templateCode);
        }
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值