sysbench對postgresql數據庫進行oltp測試

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@localhost data]# sysbench --test=oltp help     

  2. sysbench 0.4.12:  multi-threaded system evaluation benchmark  

  3.   

  4. oltp options:  

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  29.   

  30. General database options:  

  31.   

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

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

  34.   

  35. Compiled-in database drivers:  

  36.   mysql - MySQL driver  

  37.   pgsql - PostgreSQL driver  

  38.   

  39. mysql options:  

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

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

  42.   --mysql-socket=STRING         MySQL socket  

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

  44.   --mysql-password=STRING       MySQL password []  

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

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

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

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

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

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

  51.   

  52. pgsql options:  

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

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

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

  56.   --pgsql-password=STRING PostgreSQL password []  

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

4 性能測試

    4.1 準備測試數據


[plain] view plaincopy

  1. [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

  1. [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

  1. [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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章