记录一次调优经历

在重构会员域代码并重写注册接口后,遇到性能瓶颈,TPS仅为20。通过Arthas trace命令定位到执行慢的方法,发现一个查询语句未有效利用索引。进一步分析并拆分查询,成功提升查询效率,最终将TPS提高到350,满足了性能需求。
摘要由CSDN通过智能技术生成

记录一次调优经历

事由

​ 重构会员域的代码,重写了注册的接口,当测试进行压测时发现TPS只有20左右(mysql 2C/4G/SSD), 实在不满足需要,进行优化吧。

arthas发现慢的方法

使用trace命令尝试发现执行慢的方法

[arthas@6]$ `---ts=2021-04-28 10:01:28;thread_name=http-nio-8000-exec-8;id=18f;is_daemon=true;priority=5;TCCL=org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader@2371aaca
    `---[169.650847ms] xxx.xxx.domain.person.handler.WechatPersonCalculateHandler$$EnhancerBySpringCGLIB$$63ffac4f:register() [throws Exception]
        +---[169.627127ms] org.springframework.cglib.proxy.MethodInterceptor:intercept() #95 [throws Exception]
        |   `---[10.236216ms] xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler:register() [throws Exception]
        |       +---[4.791701ms] xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler:validate() #102
        |       +---[2.749295ms] xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler:analysisCalculateType() #106
        |       +---[0.005623ms] xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler$AnalysisResult:getCalculateTypeEnum() #107
        |       +---[0.004135ms] xxx.xxx.domain.person.PersonStatusEnum:getStatus() #109
        |       +---[0.004008ms] xxx.xxx.domain.person.Person:setMemberStatus() #95
        |       +---[0.006392ms] xxx.xxx.domain.person.Person:setCreateTime() #111
        |       +---[0.003577ms] xxx.xxx.domain.person.Person:setUpdateTime() #112
        |       +---[0.016866ms] xxx.xxx.domain.person.Person:setMemberRegisterTime() #113
        |       +---[0.00373ms] xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler$CalculateTypeEnum:ordinal() #115
        |       +---[2.390998ms] xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler:create() #117 [throws Exception]
        |       `---throw:java.util.concurrent.RejectedExecutionException #2063 [Task xxx.xxx.domain.person.handler.AbstractPersonCalculateHandler$$Lambda$927/1584878773@74b30230 rejected from java.util.concurrent.ThreadPoolExecutor@1b21cf63[Running, pool size = 2, active threads = 2, queued tasks = 1024, completed tasks = 95833]]

​ 发现 validate() 和 analysisCalculateType()这两个方法慢(当时,上面展示的已经是优化后的),就继续将追踪的粒度细到这两个方法(具体耗时就不贴出来了)。最终定位到一个查询语句。结合mysql中的slow_log表(我们的设置是大于1秒就会记录,记录方式是TABLE)找到具体的sql_text(三个用or关联的一个查询语句)。

​ 案例来说这个查询应该是能走索引的,后来通过explan分析,走了另一个索引,并没有走为他而设置的索引。经过几次尝试仍旧没能成功,就将几个用or关联的查询拆成了多个sql语句,分开查询,成功用上期望的索引。查询性能也随之提升。之后的压测已经提高到了350,基本满足了产品的需求。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值