当前位置:网站首页>How to check if the online query suddenly slows down

How to check if the online query suddenly slows down

2022-08-11 00:21:00 Wandering about the cat

目录

系统架构

网络层面

网络丢包,重传

网卡满 比如大字段

网络链路变长

受到IO影响

CPU/MEM

服务

资源抢占

FullGc

数据库

没有走索引

Update the same data in parallel

数据分布不均

Inappropriate query

表设计有问题

innodb 刷脏页


系统架构

  1. 网络
  2. Competition for middleware
  3. The backend service itself is slow
  4. 竞争DB本身
  5. DB查询慢

网络层面

网络丢包,重传

If dual data centers are involved,Or multi-center office scenarios,就会有这种情况.

可以长时间ping测试丢包情况.

网卡满 比如大字段

使用dstatCommand to test network congestion

网络链路变长

Involves system integration,old system involved,This type of problem can be caused if the link length is called.

如果有catThis type of distributed link tracking system,可以看,Otherwise, it's not very easy to do

受到IO影响

如果数据库服务 There may be disks caused by backup servicesIO,CPU,内存被大量占用,导致查询变慢.The essence is that other services are occupied“主服务”资源导致.

If the backend service writes files in large batches, it will cause the diskIO抢占,cause slow operation

核查:

  1. 使用top检查CPU,memory consuming process
  2. 如果是后端服务,Query the memory usage of threads,top -Hp PID
  3. 用linux dstat验证IO读写情况

CPU/MEM

CPU和内存 It is usually caused by other services being occupied

服务

资源抢占

比如redis锁,DB连接 等.If this type of concurrency is high, a large number of threads will be in a waiting state.

检查:

  1. jstack 输出java栈
  2. jmap dump快照,使用jvisualvm,jprofiler,mat等工具分析

FullGc

频繁FullGCIt will cause service lag,CPU占有率升高

检查:

  1. 用jstat -gcutil pid 查看gc数量和时间
  2. 使用dump文件分析 可能的内存泄露

数据库

没有走索引

As the database grows,If it happens that a query condition does not go through the index,查询会比较慢.

检查:

  1. 查看慢sql
  2. 查看执行计划explain

Update the same data in parallel

常见的秒杀场景:数据库并发执行update,更新同一行的动作会被其他已经持有锁的会话堵住,并且需要要进行判断会不会由于自己的加入导致死锁

数据分布不均

a=11,10条数据

a=21,10W数据,Queries are naturally different

Inappropriate query

select *** from tt limit 10000000,10;

This kind needs to be found first10000000条,然后往后找10条

调整为:

select * from tt where id >= 10 limit 10;

表设计有问题

varchar(2000) text

调整:

  1. 纵向拆分,将varchar 2000 This field is split into another table

innodb 刷脏页

InnoDB引擎采用Write Ahead Log(WAL)策略,即事务提交时,先写日志(redo log),再写磁盘.为了提高IO效率,在写日志的时候会先写buffer,然后集中flush buffer pool 到磁盘. 这个过程 We call it dirtying pages.

这个过程中就有可能导致平时执行很快的SQL突然变慢.


原网站

版权声明
本文为[Wandering about the cat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208102346596087.html