壓測 tpcb pgbench 之五 分區表(pg_pathman)壓測

os: centos 7.4
db: postgresql 10.10

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
# 
# su - postgres
Last login: Sat Oct 26 22:55:25 CST 2019 on pts/0
$
$ psql -c "select version();"
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 10.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)

create partition table

# su - postgres
$ psql

postgres=#\c pgbenchdb

pgbenchdb=# create table tmp_t1(
 id           varchar(32) not null,
 message_id   varchar(32),
 persion_id   varchar(32) not null,
 del_flag     int4,
 create_time  timestamp
)
;

pgbenchdb=# create index idx_tmp_t1_x1 on tmp_t1(id);
create index idx_tmp_t1_x2 on tmp_t1(persion_id);

pgbenchdb=# select create_hash_partitions('tmp_t1'::regclass,'persion_id',10,false);

pgbenchdb=# select partition_table_concurrently('tmp_t1'::regclass,1000,1.0);

pgbenchdb=# select set_enable_parent('tmp_t1'::regclass, false);

pgbenchdb=# \d
                     List of relations
 Schema |             Name              | Type  |  Owner   
--------+-------------------------------+-------+----------
 public | pathman_cache_stats           | view  | postgres
 public | pathman_concurrent_part_tasks | view  | postgres
 public | pathman_config                | table | postgres
 public | pathman_config_params         | table | postgres
 public | pathman_partition_list        | view  | postgres
 public | pgbench_accounts              | table | postgres
 public | pgbench_branches              | table | postgres
 public | pgbench_history               | table | postgres
 public | pgbench_tellers               | table | postgres
 public | tmp_t0                        | table | postgres
 public | tmp_t1                        | table | postgres
 public | tmp_t1_0                      | table | postgres
 public | tmp_t1_1                      | table | postgres
 public | tmp_t1_2                      | table | postgres
 public | tmp_t1_3                      | table | postgres
 public | tmp_t1_4                      | table | postgres
 public | tmp_t1_5                      | table | postgres
 public | tmp_t1_6                      | table | postgres
 public | tmp_t1_7                      | table | postgres
 public | tmp_t1_8                      | table | postgres
 public | tmp_t1_9                      | table | postgres
(21 rows)


pgbenchdb=# \d+ tmp_t1
                                               Table "public.tmp_t1"
   Column    |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
-------------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 id          | character varying(32)       |           | not null |         | extended |              | 
 message_id  | character varying(32)       |           |          |         | extended |              | 
 persion_id  | character varying(32)       |           | not null |         | extended |              | 
 del_flag    | integer                     |           |          |         | plain    |              | 
 create_time | timestamp without time zone |           |          |         | plain    |              | 
Indexes:
    "idx_tmp_t1_x1" btree (id)
    "idx_tmp_t1_x2" btree (persion_id)
Child tables: tmp_t1_0,
              tmp_t1_1,
              tmp_t1_2,
              tmp_t1_3,
              tmp_t1_4,
              tmp_t1_5,
              tmp_t1_6,
              tmp_t1_7,
              tmp_t1_8,
              tmp_t1_9

可以看到 tmp_t1_X 的10個表

pgbenchdb=# select * from pathman_config;
 partrel |    expr    | parttype | range_interval 
---------+------------+----------+----------------
 tmp_t1  | persion_id |        1 | 
(1 row)

pgbenchdb=# select * from pathman_config_params;
 partrel | enable_parent | auto | init_callback | spawn_using_bgw 
---------+---------------+------+---------------+-----------------
 tmp_t1  | f             | t    |               | f
(1 row)

pgbenchdb=# select * from pathman_partition_list;
 parent | partition | parttype |    expr    | range_min | range_max 
--------+-----------+----------+------------+-----------+-----------
 tmp_t1 | tmp_t1_0  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_1  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_2  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_3  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_4  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_5  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_6  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_7  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_8  |        1 | persion_id |           | 
 tmp_t1 | tmp_t1_9  |        1 | persion_id |           | 
(10 rows)


pgbench insert

# su - postgres
$ vim /var/lib/pgsql/scripts/par_insert.sql

\set v_id          random(1, 10000000)
\set v_message_id  random(1, 10000000)
\set v_persion_id  random(1, 100000)
\set v_del_flag    random(1, 2)
BEGIN;
INSERT INTO tmp_t1 (id, message_id, persion_id, del_flag, create_time) VALUES (:v_id, :v_message_id, :v_persion_id, :v_del_flag, CURRENT_TIMESTAMP);
END;

# su - postgres
$ /usr/pgsql-10/bin/pgbench -r -j 2 -c 4 -T 60 -P 1 -f /var/lib/pgsql/scripts/par_insert.sql pgbenchdb

starting vacuum...end.
progress: 1.0 s, 251.9 tps, lat 15.511 ms stddev 62.672
progress: 2.0 s, 610.1 tps, lat 6.549 ms stddev 1.835
progress: 3.0 s, 510.0 tps, lat 7.846 ms stddev 31.400

transaction type: /var/lib/pgsql/scripts/par_insert.sql
scaling factor: 1
query mode: simple
number of clients: 4
number of threads: 2
duration: 60 s
number of transactions actually processed: 27940
latency average = 8.597 ms
latency stddev = 25.118 ms
tps = 465.081992 (including connections establishing)
tps = 465.159698 (excluding connections establishing)
script statistics:
 - statement latencies in milliseconds:
         0.007  \set v_id          random(1, 10000000)
         0.003  \set v_message_id  random(1, 10000000)
         0.002  \set v_persion_id  random(1, 100000)
         0.002  \set v_del_flag    random(1, 2)
         0.968  BEGIN;
         1.915  INSERT INTO tmp_t1 (id, message_id, persion_id, del_flag, create_time) VALUES (:v_id, :v_message_id, :v_persion_id, :v_del_flag, CURRENT_TIMESTAMP);
         5.704  END;
		 

pgbench select

# su - postgres
$ vim /var/lib/pgsql/scripts/par_select.sql

\set v_persion_id  random(1, 100000)
\set v_del_flag    random(1, 2)
BEGIN;
select * from tmp_t1 where persion_id= cast(:v_persion_id  as varchar) and del_flag = :v_del_flag ;
END;

# su - postgres
$ /usr/pgsql-10/bin/pgbench -r -j 2 -c 4 -T 60 -P 1 -f /var/lib/pgsql/scripts/par_select.sql pgbenchdb

starting vacuum...end.
progress: 1.0 s, 3958.9 tps, lat 0.999 ms stddev 15.134
progress: 2.0 s, 6866.5 tps, lat 0.578 ms stddev 6.047
progress: 3.0 s, 6048.6 tps, lat 0.623 ms stddev 9.110

transaction type: /var/lib/pgsql/scripts/par_select.sql
scaling factor: 1
query mode: simple
number of clients: 4
number of threads: 2
duration: 60 s
number of transactions actually processed: 398795
latency average = 0.602 ms
latency stddev = 6.191 ms
tps = 6620.943141 (including connections establishing)
tps = 6621.271800 (excluding connections establishing)
script statistics:
 - statement latencies in milliseconds:
         0.001  \set v_persion_id  random(1, 100000)
         0.000  \set v_del_flag    random(1, 2)
         0.121  BEGIN;
         0.358  select * from tmp_t1 where persion_id= cast( :v_persion_id as varchar) and del_flag = :v_del_flag ;
         0.124  END;
		 

pgbench update

# su - postgres
$ vim /var/lib/pgsql/scripts/par_update.sql

\set v_persion_id  random(1, 100000)
\set v_del_flag    random(1, 2)
BEGIN;
update tmp_t1 set create_time=CURRENT_TIMESTAMP,del_flag=:v_del_flag where persion_id= cast(:v_persion_id as varchar) and del_flag = :v_del_flag ;
END;

# su - postgres
$ /usr/pgsql-10/bin/pgbench -r -j 2 -c 4 -T 60 -P 1 -f /var/lib/pgsql/scripts/par_update.sql pgbenchdb

starting vacuum...end.
progress: 1.0 s, 2331.2 tps, lat 1.666 ms stddev 3.279
progress: 2.0 s, 2169.6 tps, lat 1.747 ms stddev 3.432
progress: 3.0 s, 712.9 tps, lat 6.008 ms stddev 38.154

transaction type: /var/lib/pgsql/scripts/par_update.sql
scaling factor: 1
query mode: simple
number of clients: 4
number of threads: 2
duration: 60 s
number of transactions actually processed: 152952
latency average = 1.569 ms
latency stddev = 14.203 ms
tps = 2548.997169 (including connections establishing)
tps = 2549.207265 (excluding connections establishing)
script statistics:
 - statement latencies in milliseconds:
         0.002  \set v_persion_id  random(1, 100000)
         0.000  \set v_del_flag    random(1, 2)
         0.249  BEGIN;
         0.459  update tmp_t1 set create_time=CURRENT_TIMESTAMP,del_flag=:v_del_flag where persion_id= cast(:v_persion_id as varchar) and del_flag = :v_del_flag ;
         0.854  END;
		 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章