如今的壓力測試工具各類各樣,只要上手好幾款功能強大點的並且比較大衆化的壓力測試工具便可,如下跟你們交流下sysbench的安裝和壓力測試html
sysbench支持如下幾種測試模式:python
一、CPU運算性能mysql
二、磁盤IO性能c++
三、內存分配及傳輸速度sql
四、內存分配及傳輸速度數據庫
五、POSIX線程性能centos
六、數據庫性能(OLTP基準測試)服務器
目前sysbench主要支持mysql,drizzle,pgsql,oracle等幾種數據庫併發
下面安裝sysbenchoracle
1、 下載源碼包,安裝epel包後以便安裝bzr客戶端:
[root ~]$ rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm Retrieving http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm warning: /var/tmp/rpm-tmp.wgHSDP: Header V3 DSA/SHA1 Signature, key ID 217521f6: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%]
而後就能夠開始安裝bzr客戶端了:
如下安裝報錯了:
[root yum.repos.d]$ yum install bzr Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * epel: mirrors.ustc.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn epel | 3.7 kB 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package bzr.x86_64 0:2.1.4-2.el5 will be installed --> Processing Dependency: python(abi) = 2.4 for package: bzr-2.1.4-2.el5.x86_64 --> Processing Dependency: python-paramiko for package: bzr-2.1.4-2.el5.x86_64 --> Processing Dependency: python-elementtree for package: bzr-2.1.4-2.el5.x86_64 --> Running transaction check ---> Package bzr.x86_64 0:2.1.4-2.el5 will be installed --> Processing Dependency: python(abi) = 2.4 for package: bzr-2.1.4-2.el5.x86_64 --> Processing Dependency: python-elementtree for package: bzr-2.1.4-2.el5.x86_64 ---> Package python-paramiko.noarch 0:1.7.6-1.el5 will be installed --> Processing Dependency: python(abi) = 2.4 for package: python-paramiko-1.7.6-1.el5.noarch --> Finished Dependency Resolution Error: Package: bzr-2.1.4-2.el5.x86_64 (epel) Requires: python(abi) = 2.4 Installed: python-2.6.6-52.el6.x86_64 (@updates) python(abi) = 2.6 Available: python26-2.6.8-2.el5.x86_64 (epel) python(abi) = 2.6 Error: Package: python-paramiko-1.7.6-1.el5.noarch (epel) Requires: python(abi) = 2.4 Installed: python-2.6.6-52.el6.x86_64 (@updates) python(abi) = 2.6 Available: python26-2.6.8-2.el5.x86_64 (epel) python(abi) = 2.6 Error: Package: bzr-2.1.4-2.el5.x86_64 (epel) Requires: python-elementtree You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
解決方法把舊版本的epel源刪除,使用新的:(這個坑說白了,下載的epel源要跟本身使用系統符合,例如你用的是32位系統和64位的系統,下載epel源是不一樣的)
[root ~]$ cd /etc/yum.repos.d/ [root yum.repos.d]$ ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo epel.repo epel-testing.repo [root yum.repos.d]$ rm -rf epel.repo [root yum.repos.d]$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.eyCDYb: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] file /etc/yum.repos.d/epel-testing.repo from install of epel-release-6-8.noarch conflicts with file from package epel-release-5-4.noarch file /etc/yum.repos.d/epel.repo from install of epel-release-6-8.noarch conflicts with file from package epel-release-5-4.noarch
2、再安裝安裝bzr客戶端:
[root yum.repos.d]$ yum install bzr -y .....
....... Running Transaction Installing : python-paramiko-1.7.5-2.1.el6.noarch 1/2 Installing : bzr-2.1.1-2.el6.x86_64 2/2 Installed: bzr.x86_64 0:2.1.1-2.el6 Dependency Installed: python-paramiko.noarch 0:1.7.5-2.1.el6 Complete!
以後就能夠用bzr客戶端下載sysbench源碼了。
[root ~]$ bzr branch lp:sysbench You have not informed bzr of your Launchpad ID, and you must do this to write to Launchpad or access private data. See "bzr help launchpad-login". Branched 128 revision(s).
[root ~]$ ll -d /root/sysbench/
drwxr-xr-x 7 root root 4096 11月 25 14:45 /root/sysbench/
能夠看到,已經下載好sysbench目錄了
3、 如下準備安裝sysbench,涉及到sysbench源碼的配置和編譯,首先確認系統安裝了gcc gcc-c++編譯器:
[root sysbench]$ yum install autoconf automake libtool make cmake gcc gcc-c++ gcc4 -y
[root sysbench]$ pwd
/root/sysbench
[root sysbench]$ ./autogen.sh
查看./counfiure支持的選項再進行編譯安裝:
[root sysbench]$ ./configure --help | grep with | grep mysql
--with-mysql compile with MySQL support (default is enabled)
--with-mysql-includes path to MySQL header files
--with-mysql-libs path to MySQL libraries
[root sysbench]$ ./configure --with-mysql=/usr/local/mysql-5.5.40/ --with-mysql-includes=/usr/local/mysql-5.5.40/include/ \ > --with-mysql-libs=/usr/local/mysql-5.5.40/lib/
[root sysbench]$ make && make insall
第二種安裝方法:
在 http://sourceforge.net/projects/sysbench 下載sysbench的源碼包。
也能夠在大牛的MySQL中文網上下載:http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz
[root src]$wget http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz
[root src]$ tar zxf sysbench-0.4.12-1.1.tgz [root sysbench-0.4.12-1.1]$ ls aclocal.m4 autom4te.cache config config.status configure.ac doc libtool Makefile Makefile.in mkinstalldirs README-WIN.txt TODO autogen.sh ChangeLog config.log configure COPYING install-sh m4 Makefile.am missing README sysbench [root sysbench-0.4.12-1.1]$ ./autogen.sh
[root sysbench-0.4.12-1.1]$./configure --with-mysql=/usr/local/mysql-5.5.40/ --with-mysql-includes=/usr/local/mysql-5.5.40/include/ \
> --with-mysql-libs=/usr/local/mysql-5.5.40/lib/
[root sysbench]$ make && make insall
以上的安裝只是下載方式不一樣,安裝都是同樣的^.^
4、下面進行使用說明:
測試磁盤IOPS能夠分爲:prepare、run、cleanup三個階段:(準備數據、運行壓測、清理數據)
建立測試數據庫:
mysql> create database sbtest; Query OK, 1 row affected (0.08 sec) mysql>
[root sysbench]$ pwd /root/sysbench-0.4.12-1.1/sysbench [root sysbench]$ ./sysbench --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --mysql-socket=/data/mysql-5.5/mysql.sock \ > --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=50000 --rand-init=on prepare
若運行過程報如下錯:
./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory 解決方法: ln -s /usr/local/mysql-5.5.40/lib/libmysqlclient.so.18 /usr/lib64/
關於這幾個參數的解釋:
--test=tests/db/oltp.lua 表示調用 tests/db/oltp.lua 腳本進行 oltp 模式測試
--oltp_tables_count=10 表示會生成 10 個測試表
--oltp-table-size=50000 表示每一個測試表填充數據量爲 50000
--rand-init=on 表示每一個測試表都是用隨機數據來填充的
5、進行OLTP測試
./sysbench --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --mysql-socket=/data/mysql-5.5/mysql.sock \
> --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=50000 --num-threads=8 \
> --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=5 --max-requests=0 --percentile=99 run
參數解釋:
--num-threads=8 表示發起 8個併發鏈接
--oltp-read-only=off 表示不要進行只讀測試,也就是會採用讀寫混合模式測試
--report-interval=10 表示每10秒輸出一次測試進度報告
--rand-type=uniform 表示隨機類型爲固定模式,其餘幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累託)
--max-time=120 表示最大執行時長爲 120秒
--max-requests=0 表示總請求數爲 0,由於上面已經定義了總執行時長,因此總請求數能夠設定爲 0;也能夠只設定總請求數,不設定最大執行時長
--percentile=99 表示設定採樣比例,默認是 95%,即丟棄1%的長請求,在剩餘的99%裏取最大值
6、結果解讀:
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 8 Report intermediate results every 10 second(s) Random number generator seed is 0 and will be ignored Threads started! -- 每10秒鐘報告一次測試結果,tps、每秒讀、每秒寫、99%以上的響應時長統計 [ 10s] threads: 8, tps: 119.03, reads/s: 1677.65, writes/s: 478.93, response time: 294.40ms (99%) [ 20s] threads: 8, tps: 76.80, reads/s: 1074.47, writes/s: 307.19, response time: 495.75ms (99%) [ 30s] threads: 8, tps: 88.20, reads/s: 1232.94, writes/s: 351.61, response time: 503.98ms (99%) [ 40s] threads: 8, tps: 149.79, reads/s: 2099.73, writes/s: 600.78, response time: 396.18ms (99%) [ 50s] threads: 8, tps: 78.09, reads/s: 1093.32, writes/s: 312.38, response time: 758.12ms (99%) [ 60s] threads: 8, tps: 79.30, reads/s: 1109.76, writes/s: 316.82, response time: 509.75ms (99%) [ 70s] threads: 8, tps: 35.50, reads/s: 497.52, writes/s: 142.41, response time: 956.36ms (99%) [ 80s] threads: 8, tps: 45.40, reads/s: 635.57, writes/s: 180.39, response time: 895.67ms (99%) [ 90s] threads: 8, tps: 73.00, reads/s: 1019.58, writes/s: 290.49, response time: 693.84ms (99%) [ 100s] threads: 8, tps: 148.01, reads/s: 2069.14, writes/s: 591.64, response time: 472.85ms (99%) [ 110s] threads: 8, tps: 60.60, reads/s: 850.90, writes/s: 242.90, response time: 1052.81ms (99%) [ 120s] threads: 8, tps: 88.20, reads/s: 1237.71, writes/s: 354.20, response time: 592.94ms (99%) OLTP test statistics: queries performed: read: 145936 -- 讀總數 write: 41696 -- 寫總數 other: 20848 -- 其餘操做總數(SELECT、INSERT、UPDATE、DELETE以外的操做,例如COMMIT等) total: 208480 -- 所有總數 transactions: 10424 (86.74 per sec.) -- 總事務數(每秒事務數) deadlocks: 0 (0.00 per sec.) -- 發生死鎖總數 read/write requests: 187632 (1561.37 per sec.) -- 讀寫總數(每秒讀寫次數) other operations: 20848 (173.49 per sec.) -- 其餘操做總數(每秒其餘操做次數) General statistics: -- 一些統計結果 total time: 120.1714s -- 總耗時 total number of events: 10424 -- 共發生多少事務數 total time taken by event execution: 960.6432s -- 全部事務耗時相加(不考慮並行因素) response time: min: 5.35ms -- 最小耗時 avg: 92.16ms -- 平均耗時 max: 3955.05ms -- 最長耗時 approx. 99 percentile: 649.23ms -- 超過99%平均耗時 Threads fairness: events (avg/stddev): 1303.0000/24.81 execution time (avg/stddev): 120.0804/0.00
測試建議:
一、真實測試場景中,數據表建議不低於10個,單表數據量不低於500萬行,固然了,要視服務器硬件配置而定。若是是配備了SSD或者PCIE SSD這種高IOPS設備的話,則建議單表數據量最少不低於1億行。
二、真實測試場景中,建議持續壓測時長不小於30分鐘,不然測試數據可能不具參考意義。
想了解更多關於sysbench的相關說明,能夠參考大牛的博客:http://imysql.com/2014/10/17/sysbench-full-user-manual.shtml
做者:陸炫志 出處:xuanzhi的博客 http://www.cnblogs.com/xuanzhi201111 您的支持是對博主最大的鼓勵,感謝您的認真閱讀。本文版權歸做者全部,歡迎轉載,但請保留該聲明。 |