我正在尝试使用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
总共加载了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;
现在使用
运行脚本pgbench -c 90 -f ./sql.sql -n -t 1000
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
26个核心,30 GB,90个客户端 -
number of transactions actually processed: 90000/90000
tps = 1553.721286 (including connections establishing)
tps = 2405.664795 (excluding connections establishing)
问题: 为什么我们只有80 tps从2核增加到26核?
答案 0 :(得分:2)
我在postgres irc上问了同样的问题。
社区确信我最大化了客户端pgbench,他们建议在pgbench中使用-j4
并且tps每秒增加到23k。
答案 1 :(得分:-1)
因为个人SELECT
只能在一个核心上运行的一个进程中运行。添加额外内核的功能是允许执行多个同时操作。因此,如果您在数据库中抛出(比方说)1,000个并发查询,它们将在26个核心而不是2个核心上执行得更快。