【发布时间】:2019-10-21 06:15:30
【问题描述】:
我用的是VPS服务器,cpu资源一直显示99%,怎么找mysql查询哪个cpu资源比较消耗。
【问题讨论】:
标签: mysql resources magento-1.9 cpu-usage vps
我用的是VPS服务器,cpu资源一直显示99%,怎么找mysql查询哪个cpu资源比较消耗。
【问题讨论】:
标签: mysql resources magento-1.9 cpu-usage vps
首先你应该 ssh 进入服务器然后检查高处理查询:
连接mysql -u root -p
输入SHOW PROCESSLIST; 您也可以使用SHOW FULL PROCESSLIST 来查看完整的查询。
这将显示当时正在运行的所有查询。
第二:你应该启用Slow queries log并检查它。确保你没有任何查询锁定键表太久。
第三:你应该检查你的mysql用户并确保没有人远程访问它。
最后:启用默认的 magento 分析器并检查缓慢的进程。 为了启用它,请转到:
System > Configuration > Advanced > Developer > Debug > Profiler > Yes
然后打开 Magento 安装的根 index.php 文件,然后查找已注释的 Varien_Profiler::enable(); 部分并取消注释。
如果要启用 sql 分析,请将 <profiler>true</profiler> 添加到 app/etc/local.xml
例子:
<resources>
<db>
<table_prefix><![CDATA[]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[root]]></username>
<password><![CDATA[]]></password>
<dbname><![CDATA[magento_1_8_1_0]]></dbname>
<initStatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdoType><![CDATA[]]></pdoType>
<active>1</active>
<profiler>true</profiler>
</connection>
</default_setup>
</resources>
您甚至可以通过添加来分析单个代码
//First, enable the profiler
Varien_Profiler::enable();
//Second, start the profiler with a unique label
Varien_Profiler::start('LabelForCodeFragmentToProfile');
///... here some code we like to get statistics for
//next, stop your profiler with the same label
Varien_Profiler::stop('LabelForCodeFragmentToProfile');
//Last, disable your profiler
Varien_Profiler::disable();
【讨论】:
【讨论】: