【问题标题】:How to find CPU and RAM usage for running a query in PostgreSQL and MySQL如何查找在 PostgreSQL 和 MySQL 中运行查询的 CPU 和 RAM 使用情况
【发布时间】:2020-01-04 13:38:30
【问题描述】:

我正在尝试计算安装在 ubuntu 18.04 中的 PostgreSQL 和 MySQL 的 RAM 和 CPU 使用率。在两个数据库中运行以下查询时,工作负载相同 (TPCH)。

select l_returnflag, l_linestatus, sum(l_quantity) as sum_qty, sum(l_extendedprice) as sum_base_price, sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, avg(l_quantity) as avg_qty, avg(l_extendedprice) as avg_price, avg(l_discount) as avg_disc, count(*) as count_order from LINEITEM where l_shipdate <= date '1998-12-01' - interval '108' day group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus;

在 PostgreSQL 中,我使用以下命令来捕获更改。

ps -a -U root -u postgres -0 pid,cmd,pcpu,pmem,thcount,psr|grep "postgres: 10/main: postgres"|grep -v "grep"

为 postgreSQL 捕获的测量结果是:

Response time: 6270,516 ms
%RAM: 0,45
%CPU: 44,009
Threads:1 
Cores used: 4

在 Mysql 中,我使用以下命令来捕获更改。

ps -e -0 pid,cmd,pcpu,pmem,thcount,psr|grep "/usr/sbin/mysqld --daemoniz"|grep -v "grep"

为 Mysql 捕获的测量值是:

Response time: 13348,161 ms
%RAM: 3.82
%CPU: 99.76
Threads:28
Cores used: 4

如果我再次捕获指标,两个数据库的 %CPU 都会发生变化(大约 10% 到 30% 的差异),这种变化的原因是什么?

与 postgreSQL 相比,Mysql 中查询的 RAM、CPU 和响应时间百分比非常高,这背后的原因是什么?或者有其他方法吗?

【问题讨论】:

  • 请考虑发布 A) SHOW CREATE TABLE lineitems;和 B) EXPLAIN SELECT(您的查询),这样我们就可以看到优化器认为您的查询将如何针对每个系统进行处理。
  • 使用 ubuntu 操作系统,在命令提示符下,您可以使用 top 来确定进程运行时使用的 CPU% 吗?
  • @WilsonHauck,'top' 和 'ps' 给出了相同的值,我正在使用 'ps' 命令专门使用它的进程名称来获取 DBMS 进程。
  • 发布的剪辑中有没有 pid 和 cmd 的原因?请考虑发布 A) SHOW CREATE TABLE lineitems;和 B) EXPLAIN SELECT(您的查询),这样我们就可以看到优化器认为您的查询将如何针对每个系统进行处理。

标签: mysql linux database postgresql ubuntu


【解决方案1】:

差异可能与缓存和每个数据库引擎的不同优化有关。

这里是如何清除 Postgres 中的缓存:

service postgresql stop
sync
echo 3 > /proc/sys/vm/drop_caches
service postgresql start

在 MYSQL 中:

RESET QUERY CACHE;

要随着时间的推移监控过程,您可以使用方法suggested in this post

【讨论】:

  • 我检查了缓存文件,两个DBMS文件都是空的。
猜你喜欢
  • 1970-01-01
  • 2019-10-13
  • 2021-11-05
  • 2013-07-27
  • 2010-10-03
  • 2010-09-21
  • 1970-01-01
相关资源
最近更新 更多