客户端通过nodejs向postgreSQL和mysql发送超过30万条异步插入查询。
postgreSQL 比 mysql 慢得多! mysql 服务器将使用超过 50% 的 cpu,但 postgresql 服务器仅使用大约 10%。
服务器硬件为8核CPU和8 RAM,两台服务器具有相同的硬件设置。
客户端配置如下
// mysql
const mysql = require('mysql2');
const pool = mysql.createPool({
host: 'host',
user: 'dev_user',
database: 'testdb',
password: 'password',
waitForConnections: true,
connectionLimit: 10,
maxIdle: 10,
idleTimeout: 60000,
queueLimit: 0,
enableKeepAlive: true,
keepAliveInitialDelay: 0
}).promise();
// postgresql
const Pool = require('pg-pool');
var pool = new Pool({
database: 'testdb',
host: 'host',
user: 'dev_user',
password: 'pasword',
port: 5432,
max: 10,
idleTimeoutMillis: 10000,
connectionTimeoutMillis: 600000,
maxUses: 75000
});
mysql服务器cpu使用情况
postgresql 服务器 CPU 使用情况
为什么会造成这种情况呢? 我如何调整 postgreSQL 以使用更多 CPU 资源?
通过设置
synchronous_commit = off
使PostgreSQL对磁盘施加较小的压力。然后它就有机会使用更多的CPU。