加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sysbench对postgresql数据库进行oltp测试

发布时间:2020-12-13 17:17:57 所属栏目:百科 来源:网络整理
导读:1 简介 sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/ PostgreSQL /Drizzle。 它主要包括以下几种方式的测试: 1.cpu性能 2.磁盘io性能 3.调度程序性能 4.内存分配及传输速度 5.P

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

  1. [root@localhostdata]#sysbench--test=oltphelp

  2. sysbench0.4.12:multi-threadedsystemevaluationbenchmark

  3. oltpoptions:

  4. --oltp-test-mode=STRINGtesttypetouse{simple,complex,nontrx,sp}[complex]

  5. --oltp-reconnect-mode=STRINGreconnectmode{session,transaction,query,random}[session]

  6. --oltp-sp-name=STRINGnameofstoreproceduretocallinSPtestmode[]

  7. --oltp-read-only=[on|off]generateonly'read'queries(donotmodifydatabase)[off]

  8. --oltp-skip-trx=[on|off]skipBEGIN/COMMITstatements[off]

  9. --oltp-range-size=Nrangesizeforrangequeries[100]

  10. --oltp-point-selects=Nnumberofpointselects[10]

  11. --oltp-simple-ranges=Nnumberofsimpleranges[1]

  12. --oltp-sum-ranges=Nnumberofsumranges[1]

  13. --oltp-order-ranges=Nnumberoforderedranges[1]

  14. --oltp-distinct-ranges=Nnumberofdistinctranges[1]

  15. --oltp-index-updates=Nnumberofindexupdate[1]

  16. --oltp-non-index-updates=Nnumberofnon-indexupdates[1]

  17. --oltp-nontrx-mode=STRINGmodefornon-transactionaltest{select,update_key,update_nokey,insert,delete}[select]

  18. --oltp-auto-inc=[on|off]whetherAUTO_INCREMENT(orequivalent)shouldbeusedonidcolumn[on]

  19. --oltp-connect-delay=Ntimeinmicrosecondstosleepafterconnectiontodatabase[10000]

  20. --oltp-user-delay-min=Nminimumtimeinmicrosecondstosleepaftereachrequest[0]

  21. --oltp-user-delay-max=Nmaximumtimeinmicrosecondstosleepaftereachrequest[0]

  22. --oltp-table-name=STRINGnameoftesttable[sbtest]

  23. --oltp-table-size=Nnumberofrecordsintesttable[10000]

  24. --oltp-dist-type=STRINGrandomnumbersdistribution{uniform,gaussian,special}[special]

  25. --oltp-dist-iter=Nnumberofiterationsusedfornumbersgeneration[12]

  26. --oltp-dist-pct=Npercentageofvaluestobetreatedas'special'(forspecialdistribution)[1]

  27. --oltp-dist-res=Npercentageof'special'valuestouse(forspecialdistribution)[75]

  28. GeneraldatabaSEOptions:

  29. --db-driver=STRINGspecifiesdatabasedrivertouse('help'togetlistofavailabledrivers)

  30. --db-ps-mode=STRINGpreparedstatementsusagemode{auto,disable}[auto]

  31. Compiled-indatabasedrivers:

  32. mysql-MySQLdriver

  33. pgsql-PostgreSQLdriver

  34. mysqloptions:

  35. --mysql-host=[LIST,...]MySQLserverhost[localhost]

  36. --mysql-port=NMySQLserverport[3306]

  37. --mysql-socket=STRINGMySQLsocket

  38. --mysql-user=STRINGMySQLuser[sbtest]

  39. --mysql-password=STRINGMySQLpassword[]

  40. --mysql-db=STRINGMySQLdatabasename[sbtest]

  41. --mysql-table-engine=STRINGstorageenginetouseforthetesttable{myisam,innodb,bdb,heap,ndbcluster,federated}[innodb]

  42. --mysql-engine-trx=STRINGwhetherstorageengineusedistransactionalornot{yes,no,auto}[auto]

  43. --mysql-ssl=[on|off]useSSLconnections,ifavailableintheclientlibrary[off]

  44. --myisam-max-rows=Nmax-rowsparameterforMyISAMtables[1000000]

  45. --mysql-create-options=STRINGadditionaloptionspassedtoCREATETABLE[]

  46. pgsqloptions:

  47. --pgsql-host=STRINGPostgreSQLserverhost[localhost]

  48. --pgsql-port=NPostgreSQLserverport[5432]

  49. --pgsql-user=STRINGPostgreSQLuser[sbtest]

  50. --pgsql-password=STRINGPostgreSQLpassword[]

  51. --pgsql-db=STRINGPostgreSQLdatabasename[sbtest]

4 性能测试

4.1 准备测试数据


[plain]copy

  1. [root@localhostdata]#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=10prepare



4.2 开始测试

[plain]copy

  1. [root@localhostdata]#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=10run


PostgreSQL tps : 1001978(注:因在虚拟机上操作,仅为演示,不做性能对比参考)

4.3 清理测试数据

[plain]copy

  1. [root@localhostdata]#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=10cleanup

-----------------------------------------------------------------------------

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读