检查MySQL内存使用情况
=========================================================================================================================
#启用收集内存指标
UPDATE setup_instruments SET ENABLED = 'YES' WHERE NAME LIKE 'memory/%';
#查看运行sys schema里面内存分配的报告
select event_name,current_alloc,high_alloc from sys.memory_global_by_current_bytes where current_count > 0;
#获得每个事件更高级别活动的总体报告
select substring_index(substring_index(event_name,'/',2),'/',-1) as event_type,
round(sum(current_number_of_bytes_used) / 1024/1024, 2) as MB_CURRENTLY_USED
from performance_schema.memory_summary_global_by_event_name
group by event_type
having
mb_currently_used >0
=========================================================================================================================
现在我们可以检查MySQL内部的东西来寻找潜在的MySQL内存泄漏情况:
MySQL在很多地方分配内存,尤其:
表缓存
Performance_schema(运行:show engine performance_schema status 然后看最后一行),这可能在系统RAM比较少(1G或更少)时的可能原因。
InnoDB(运行show engine innodb status 检查 buffer pool部分,为buffer pool及相关缓存分配的内存)
内存中的临时表(查看所有内存表:select * from information_schema.tables where engine='MEMORY')
预处理语句,当他们没有被释放时(通过运行show global status like 'Com_prepare_sql'和show global status like 'Com_dealloc_sql'来检查通过deallocate命令释放的预处理语句)
The good news is: starting with MySQL 5.7 we have memory allocation in performance_schema. Here is how we can use it.
好消息是,从5.7开始我们可以通过performance_schema查看内存的分配情况。下面就展示如何使用它:
First, we need to enable collecting memory metrics. Run:
UPDATE setup_instruments SET ENABLED = 'YES' WHERE NAME LIKE 'memory/%';
Run the report from sys schema:
select event_name, current_alloc, high_alloc from sys.memory_global_by_current_bytes where current_count > 0;
Usually this will give you the place in code when memory is allocated. It is usually self-explanatory. In some cases we can search for bugs or we might need to check the MySQL source code.
首先,我们需要启用收集内存指标,运行如下语句:
UPDATE setup_instruments SET ENABLED = 'YES' WHERE NAME LIKE 'memory/%';
运行sys schema里面的报告
select event_name,current_alloc,high_alloc from sys.memory_global_by_current_bytes where current_count > 0;
通常,这将在分配内存时为你提供代码,它通常是不言自明的。在某些情况下,我们可以搜索错误,或者我们可能需要检查MySQL源代码。
For example, for the bug where memory was over-allocated in triggers (https://bugs.mysql.com/bug.php?id=86821) the select shows:
例如,有一个过度为触发器分配内存的bug:
https://bugs.mysql.com/bug.php?id=86821
查询的显示如下:
The largest chunk of RAM is usually the buffer pool but ~3G in stored procedures seems to be too high.
分配最大一块内存通常是buffer pool,但是约3G的存储过程似乎有点太高了.
According to the MySQL source code documentation, sp_head represents one instance of a stored program which might be of any type (stored procedure, function, trigger, event). In the above case we have a potential memory leak.
根据MySQL source code documentation,sp_head表示存储程序里面的一个实例(比如存储过程、函数、触发器,及事件)。在上面的例子,我们有潜在的内存泄漏的风险。
In addition we can get a total report for each higher level event if we want to see from the birds eye what is eating memory:
另外,我们想要鸟瞰什么吃掉了内存,我们可以获得每个事件更高级别活动的总体报告。
检查MySQL内存使用情况的更多相关文章
- mysql内存使用情况
可以直接使用top命令后,查看%MEM的内容.可以选择按进程查看或者按用户查看,如想查看oracle用户的进程内存使用情况的话可以使用如下的命令: (1)top top命令是Linux下常用的性能分析 ...
- Linux中检查内存使用情况的命令
Linux操作系统包含大量工具,所有这些工具都可以帮助您管理系统.从简单的文件和目录工具到非常复杂的安全命令,在Linux上没有太多不能做的事情.而且,虽然普通桌面用户可能不需要在命令行熟悉这些工具, ...
- 线上mysql内存持续增长直至内存溢出被killed分析(已解决)
来新公司前,领导就说了,线上生产环境Mysql库经常会发生日间内存爆掉被killed的情况,结果来到这第一天,第一件事就是要根据线上服务器配置优化配置,同时必须找出现在mysql内存持续增加爆掉的原因 ...
- 检查MySQL主从复制运行状态
脚本思路: 1.使用MySQL客户端命令"mysql"直接在命令行中运行MySQL指令"show slave status\G;"来查看MySQL主从复制状态信 ...
- Linux Centos下查看cpu、磁盘、内存使用情况,关闭MySQL日志
Linux Centos下查看cpu.磁盘.内存使用情况,关闭MySQL日志 lsblk 查看分区和磁盘df -h 查看空间使用情况fdisk -l 分区工具查看分区信息cfdisk /dev/sda ...
- 阿里云下 centos7下启动程序总是被killed ,看内存占用情况以检查哪些服务存在问题并调整参数作调优
很久不搭理自己的网站了,几天突然发现启动程序总是被killed, 于是查看了系统日志 vi /var/log/messages 发现出现 kernel: Out of memory: Kill pro ...
- hdfs对namenode format 之后 应该首先检查内存消耗情况,以判断是否支持开启yarn
http://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-common/yarn-default.xml 3.0.0 yarn.sc ...
- 如何检查 Android 应用的内存使用情况
Android是为移动设备而设计的,所以应该关注应用的内存使用情况.尽管Android的Dalvik虚拟机会定期执行垃圾回收操作,但这也不意味着就可以忽视应用在何时何处进行内存分配和释放.为了提供良好 ...
- 【shell脚本】检查内存使用情况===chenkMen.sh
检查内存使用情况,当内存可使用等于100时,释放缓存 [root@localhost thy]# cat checkMem.sh #!/bin/bash #防止内存溢出问题 used=`free -m ...
随机推荐
- mycat练习笔记
学习要趁早,装逼莫等老. 刚刚开始接触到mycat, 当然要学习一下了.拿它来设置 mysql 的读写分离,分库分表,以及集群等. 官网: http://www.mycat.io/ 有详情介绍,有G ...
- Centos6.5 安装 RabbitMQ 3.7.11
RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python.Ruby..NET.Java.JMS.C.PHP.ActionScript.XMPP.STO ...
- JavaScript 中的常用12种循环遍历(数组或对象)的方法
1.for 循环 let arr = [1,2,3]; for (let i=0; i<arr.length; i++){ console.log(i,arr[i]) } // 0 1 // 1 ...
- Breadth-first search
given a graph G and a distinguished source vertex s, breadth-firstsearch systematically explores th ...
- vue生命周期中created和mounted的区别
created在渲染页面之前使用,通常是用来渲染页面 mounted通常是在渲染页面之后,用来操作dom节点 通常情况下使用created比较多,使用mounted相对少一些,一些情况使用mounte ...
- 一道笔试题来理顺Java中的值传递和引用传递
题目如下: private static void change(StringBuffer str11, StringBuffer str12) { str12 = str11; str11 = ...
- NSArray NSMutableArray
NSArray 或者 NSMUtableArray 去除重复的数据: 原来集合操作可以通过valueForKeyPath来实现的,去重可以一行代码实现: [array valueForKeyPath: ...
- 20个可用于商业用途的免费 CC0 授权的高分辨率图库
如今国人已经越来越重视版权了. 而用CC0 授权的图片不用担心版权的问题,那么什么是CC0授权呢?简单来说就是「公共领域贡献宣告」授权,当创作者在自身作品使用 CC0 授权时,代表于符合法律规定的最大 ...
- 使用command line测试网速
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py --no ...
- 二、Windows 下 ShellCode 编写初步
第二章.Windows 下 ShellCode 编写初步 (一)shellcode 定义:最先的 Shell 指的是人机交互界面,ShellCode 是一组能完成我们想要的功能的机器代码,通常以十六进 ...