我正在试用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 10002个核心,7.5 GB,90客户端--
OUTPUT:
number of transactions actually processed: 90000/90000
tps = 1519.690555 (including connections establishing)
tps = 2320.408683 (excluding connections establishing26核,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个?
发布于 2017-05-09 06:45:18
我在postgres irc上也问了同样的问题。
社区确信我正在优化客户端pgbench,他们建议在pgbench中使用-j4,tps提高到每秒23k。
发布于 2017-05-01 16:45:31
因为单个SELECT只在一个核心上运行的一个进程中运行。添加额外的核心可以同时执行多个操作。因此,如果要向数据库抛出1,000个同时查询,它们将在26个核上执行得更快,而不是在两个核上执行。
https://stackoverflow.com/questions/43718390
复制相似问题