目录
4.2 测试4个线程,每个线程100W,每1000条提交一次 4
5.2 测试四个线程写入同一个表,每个线程100W,1000条提交一次 7
硬件信息请查看以下链接
https://blog.csdn.net/xfg0218/article/details/82785196
测试代码请下载:
链接: https://pan.baidu.com/s/1oOpPfuEDGMc9HboffH2ZGw 提取码: saf5
参考资料:https://blog.csdn.net/dinopan/article/details/81511974
create table t_person4insert
(
id bigint,
name varchar(255)
)
distributed by(id);
请在代码中找到com.chinadaas.Person1Thread类即可测试
person cost = 2748667ms ÷ 1000 = 2748.667s
stagging=# select pg_size_pretty(pg_relation_size('t_person'));
pg_size_pretty
----------------
51 MB
(1 row)
stagging=# select count(*) from t_person;
count
---------
1000000
(1 row)
51 ÷ 2748667 × 1000 ≈ 0.0185M/S
1000000 ÷ 2748667 × 1000 ≈ 363.81行/S
create table t_person4insert1
(
id bigint,
name varchar(255)
)
distributed by(id);
create table t_person4insert2
(
id bigint,
name varchar(255)
)
distributed by(id);
create table t_person4insert3
(
id bigint,
name varchar(255)
)
distributed by(id);
create table t_person4insert4
(
id bigint,
name varchar(255)
)
distributed by(id);
请在代码中找到com.chinadaas.Person4Thread类即可测试
四个线程整体的耗时为:3240611ms ≈ 3240 s
stagging=# select pg_size_pretty(pg_relation_size('t_person4insert1'));
pg_size_pretty
----------------
51 MB
(1 row)
stagging=# select pg_size_pretty(pg_relation_size('t_person4insert2'));
pg_size_pretty
----------------
51 MB
(1 row)
stagging=# select pg_size_pretty(pg_relation_size('t_person4insert3'));
pg_size_pretty
----------------
51 MB
(1 row)
stagging=# select pg_size_pretty(pg_relation_size('t_person4insert4'));
pg_size_pretty
----------------
51 MB
(1 row)
Time: 31.728 ms
stagging=# select count(*) from t_person4insert1;
count
---------
1000000
(1 row)
Time: 66.177 ms
stagging=# select count(*) from t_person4insert2;
count
---------
1000000
(1 row)
Time: 39.403 ms
stagging=# select count(*) from t_person4insert3;
count
---------
1000000
(1 row)
Time: 39.403 ms
stagging=# select count(*) from t_person4insert4;
count
---------
1000000
(1 row)
Time: 70.558 ms
51 ÷ 3240611 × 1000 ≈ 0.0157M/S
1000000 ÷ 3240611 × 1000 ≈ 308.58行/S
以下是单线程结果
51 ÷ 2748667 × 1000 ≈ 0.0185M/S
1000000 ÷ 2748667 × 1000 ≈ 363.81行/S
以下是多线程结果
51 ÷ 3240611 × 1000 ≈ 0.0157M/S
1000000 ÷ 3240611 × 1000 ≈ 308.58行/S
四个线程的吞吐量比单线程慢了很多
create table t_person4insertrange
(
id bigint,
name varchar(255)
)
distributed by(id);
请在代码中找到com.chinadaas.PersonRangegThread类即可测试
total cost = 3164341ms ≈ 3164s
stagging=# select pg_size_pretty(pg_relation_size('t_person4insertrange'));
pg_size_pretty
----------------
200 MB
(1 row)
Time: 7.443 ms
stagging=# select count(*) from t_person4insertrange;
count
---------
4000000
(1 row)
Time: 162.728 ms
200 ÷ 3164341 × 1000 ≈ 0.063M/S
4000000 ÷ 3164341 × 1000 ≈ 1264行/S
在以上的结果中可以看出使用多线程写入单个表的速度还是可以的,达到1264行/S
详细的测试结果请查看:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。