【发布时间】: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