Postgres性能不随核心数量的增加而增加

Bhu*_*van 10 postgresql google-cloud-sql

我正在尝试postgres google-cloud-sql并加载了一个简单的学校架构

 CREATE TABLE school ( 
    id SERIAL NOT NULL PRIMARY KEY,
    name TEXT NOT NULL
);

CREATE TABLE class ( 
    id SERIAL NOT NULL PRIMARY KEY,
    name TEXT,
    school_id INTEGER NOT NULL REFERENCES school
);

CREATE TABLE student ( 
    id SERIAL NOT NULL PRIMARY KEY,
    name TEXT,
    class_id INTEGER NOT NULL REFERENCES class
);

-- ALL id and foreign keys have indexs
Run Code Online (Sandbox Code Playgroud)

总共加载了约1500万行,1500所学校,每所学校500班,每班200名学生.

之后创建一个简单的pgbench脚本

\setrandom sId1 1 20000000
\setrandom sId2 1 20000000
\setrandom sId3 1 20000000

select count(*) from school s 
join class c on s.id=c.school_id 
join student stu on c.id=stu.class_id where s.id=:sId1;

select count(*) from school s 
join class c on s.id=c.school_id 
join student stu on c.id=stu.class_id where s.id=:sId2;

select count(*) from school s 
join class c on s.id=c.school_id 
join student stu on c.id=stu.class_id where s.id=:sId3;
Run Code Online (Sandbox Code Playgroud)

现在运行脚本

pgbench -c 90 -f ./sql.sql  -n -t 1000
Run Code Online (Sandbox Code Playgroud)

2核,7.5 GB,90客户端 -

OUTPUT:
number of transactions actually processed: 90000/90000
tps = 1519.690555 (including connections establishing)
tps = 2320.408683 (excluding connections establishing
Run Code Online (Sandbox Code Playgroud)

26个核心,30 GB,90个客户端 -

number of transactions actually processed: 90000/90000
tps = 1553.721286 (including connections establishing)
tps = 2405.664795 (excluding connections establishing)
Run Code Online (Sandbox Code Playgroud)

问: 为什么我们只有80 tps从2核增加到26核?

Bhu*_*van 2

我在 postgres irc 上问了同样的问题。

社区确信我已经最大化了客户端 pgbench 的性能,他们建议-j4在 pgbench 中使用,并且 tps 增加到每秒 23k。