您的位置:首页 > 数据库 > SQL

sysbench对postgresql数据库进行oltp测试

2015-06-11 13:45 716 查看
1 简介
sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL/Drizzle。
它主要包括以下几种方式的测试:
1.cpu性能
2.磁盘io性能
3.调度程序性能
4.内存分配及传输速度
5.POSIX线程性能
6.数据库性能(OLTP基准测试)
本节主要演示使用sysbench对postgresql数据库进行oltp测试,关于sysbench的详细讲解请参考我前面的文章,【http://blog.csdn.net/jesseyoung/article/details/38418883】,这里不再赘述。
2 测试软硬件环境
操作系统:CentOS release 6.5 (Final)
linux内核:2.6.32-431.el6.x86_64
数据库版本:PostgreSQL 9.3.5
SYSBENCH版本:0.4
CPU:Intel(R) Core(TM) i3 CPU M 380 @ 2.53GHz 4核
硬盘:128GB
内存:2GB
3 oltp测试相关参数

Installation
./configure --prefix=/usr/local/sysbench/ --with-pgsql--with-pgsql-includes=/usr/local/pgsql/include/--with-pgsql-libs=/usr/local/pgsql/lib/ --without-mysql

[plain] view plaincopy

[root@localhost data]# sysbench --test=oltp help

sysbench 0.4.12: multi-threaded system evaluation benchmark

oltp options:

--oltp-test-mode=STRING test type to use {simple,complex,nontrx,sp} [complex]

--oltp-reconnect-mode=STRING reconnect mode {session,transaction,query,random} [session]

--oltp-sp-name=STRING name of store procedure to call in SP test mode []

--oltp-read-only=[on|off] generate only 'read' queries (do not modify database) [off]

--oltp-skip-trx=[on|off] skip BEGIN/COMMIT statements [off]

--oltp-range-size=N range size for range queries [100]

--oltp-point-selects=N number of point selects [10]

--oltp-simple-ranges=N number of simple ranges [1]

--oltp-sum-ranges=N number of sum ranges [1]

--oltp-order-ranges=N number of ordered ranges [1]

--oltp-distinct-ranges=N number of distinct ranges [1]

--oltp-index-updates=N number of index update [1]

--oltp-non-index-updates=N number of non-index updates [1]

--oltp-nontrx-mode=STRING mode for non-transactional test {select, update_key, update_nokey, insert, delete} [select]

--oltp-auto-inc=[on|off] whether AUTO_INCREMENT (or equivalent) should be used on id column [on]

--oltp-connect-delay=N time in microseconds to sleep after connection to database [10000]

--oltp-user-delay-min=N minimum time in microseconds to sleep after each request [0]

--oltp-user-delay-max=N maximum time in microseconds to sleep after each request [0]

--oltp-table-name=STRING name of test table [sbtest]

--oltp-table-size=N number of records in test table [10000]

--oltp-dist-type=STRING random numbers distribution {uniform,gaussian,special} [special]

--oltp-dist-iter=N number of iterations used for numbers generation [12]

--oltp-dist-pct=N percentage of values to be treated as 'special' (for special distribution) [1]

--oltp-dist-res=N percentage of 'special' values to use (for special distribution) [75]

General database options:

--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)

--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

Compiled-in database drivers:

mysql - MySQL driver

pgsql - PostgreSQL driver

mysql options:

--mysql-host=[LIST,...] MySQL server host [localhost]

--mysql-port=N MySQL server port [3306]

--mysql-socket=STRING MySQL socket

--mysql-user=STRING MySQL user [sbtest]

--mysql-password=STRING MySQL password []

--mysql-db=STRING MySQL database name [sbtest]

--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]

--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]

--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]

--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]

--mysql-create-options=STRING additional options passed to CREATE TABLE []

pgsql options:

--pgsql-host=STRING PostgreSQL server host [localhost]

--pgsql-port=N PostgreSQL server port [5432]

--pgsql-user=STRING PostgreSQL user [sbtest]

--pgsql-password=STRING PostgreSQL password []

--pgsql-db=STRING PostgreSQL database name [sbtest]

4 性能测试

4.1 准备测试数据
[plain] view plaincopy

[root@localhost data]# sysbench --test=oltp --oltp-table-size=100000 --pgsql-host=127.0.0.1 --pgsql-port=5432 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --db-driver=pgsql --max-requests=1000000 --oltp-test-mode=simple --oltp-reconnect-mode=session --num-threads=10 prepare



4.2 开始测试

[plain] view plaincopy

[root@localhost data]# sysbench --test=oltp --oltp-table-size=100000 --pgsql-host=127.0.0.1 --pgsql-port=5432 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --db-driver=pgsql --max-requests=1000000 --oltp-test-mode=simple --oltp-reconnect-mode=session --num-threads=10 run



PostgreSQL tps : 1001978(注:因在虚拟机上操作,仅为演示,不做性能对比参考)
4.3 清理测试数据[plain] view plaincopy

[root@localhost data]# sysbench --test=oltp --oltp-table-size=100000 --pgsql-host=127.0.0.1 --pgsql-port=5432 --pgsql-user=postgres --pgsql-password=postgres --pgsql-db=postgres --db-driver=pgsql --max-requests=1000000 --oltp-test-mode=simple --oltp-reconnect-mode=session --num-threads=10 cleanup



-----------------------------------------------------------------------------
1. 查看数据库大小。
select pg_size_pretty(pg_database_size('db_name'));

通过 pgAdmin 我们可以看到,在 PostgreSQL(pg_catalog) 下有如下两个视图:
pg_stat_user_tables,pg_stat_user_indexes。可以通过它们来查看表及索引的大小。

2. 查看所有索引的大小。
select indexrelname,
pg_size_pretty(pg_relation_size(indexrelname))
from pg_stat_user_indexes
where schemaname = 'public'
order by pg_relation_size(indexrelname) desc;

3. 查所有表的大小。
select relname,
pg_size_pretty(pg_relation_size(relname))
from pg_stat_user_tables
where schemaname = 'public'
order by pg_relation_size(relname) desc;

select relname, pg_size_pretty(pg_relation_size(relid))
from pg_stat_user_tables
where schemaname = 'public'
order by pg_relation_size(relid) desc;

4. 查看单个表的大小。
select pg_size_pretty(pg_relation_size('table_name'));

5. 查看Postgresql连接数
SELECT count(*) FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;

6. 查看postgreSQL进程
SELECT pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_activity(s.backendid) AS current_query FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
杀掉某个进程为: select pg_cancel_backend('2056')

7. postgresql随机查询获取数据
比如是表test,则随机查询语句为: select * from test order by random() limit 1;
如果是随机获取5条记录,则 select * from test order by random() limit 5;

8.优化可见性判断
如果是刚插完数据(sysbench prepare),马上就做读的测试,通常会看到有比较大的写,原因是PostgreSQL为了在读数据时优化可见性判断,你可以对表做一次全表扫描 explain analyze select * from sbtest1;执行checkpoint;命令,然后再测试,写应该就能消失了。可见性判断可以见我的blog: http://osdbablog.sinaapp.com/94.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: