zoukankan      html  css  js  c++  java
  • MySQL-进程占用CPU资源高问题分析

    问题分析

    实时问题分析,历史问题分析可以通过慢查询日志或genrary日志分析SQL语句的性能

    从操作系统级命令检查资源使用情况

    top命令检查系统资源使用情况

    top
    

    image-20210604105534507

    检查mysqld进程信息

    ps -ef|grep mysqld
    

    image-20210604104708395

    检查mysql线程资源占用情况

    # top -H -p <mysql进程id>
    top -H -p 6836
    

    image-20210604104535167

    从DB层面检查分析

    检查数据库当前连接进程信息

    show processlist;
    show full processlist;
    
    show status like 'Thread%';
    

    登陆mysql中查询定位SQL

    SELECT a.THREAD_OS_ID,b.user,b.host,b.db,b.command,b.time,b.state, b.info
    FROM performance_schema.threads a,information_schema.processlist b
    WHERE b.id = a.processlist_id
      and a.THREAD_OS_ID = 6886  -- 上图top命令获取到的 OS_Thread_PID
    ;
    

    image-20210604105140790

    分析上面的SQL的执行计划

    explain SELECT * FROM t_log_details WHERE log_id= 255 AND type=2;
    

    image-20210604105403672

    从上面的语句中,需要从表中扫描792060行记录,消耗的逻辑IO高

    检查表结构

    show create table t_log_detailsG
    
    show index from t_log_details;
    

    建议添加索引优化SQL。

    解决方案

    1. 建议在t_log_details表的log_id列创建索引
  • 相关阅读:
    R语言学习——数据框
    R语言学习——数组
    R语言学习——矩阵
    R语言学习——向量
    SSM的项目结构
    simple-spring-memcached简介
    Arrays
    AbstractCollection 类
    Collections 类
    Map接口
  • 原文地址:https://www.cnblogs.com/binliubiao/p/14848883.html
Copyright © 2011-2022 走看看