显示标签为“benchmark”的博文。显示所有博文
显示标签为“benchmark”的博文。显示所有博文

2014年5月3日星期六

MySQL基準與mysqlslap

Original post: http://anothermysqldba.blogspot.com/2014/05/mysql-benchmark-with-mysqlslap.html

因此,基準不同的MySQL查詢在你的數據庫是一個明智的做法。 這應該不用說。 雖然我們優化查詢,我們可以利用解釋(和擴展)的最佳服用時間為基準他們應該證明是有益的。 

這是執行mysqlslap語句的一個簡單的例子。 

對於這個例子,我從MySQL載入世界資料庫。 ( http://dev.mysql.com/doc/index-other.html 

我創建了一個連接的所有三個表,並把它放到/ tmp目錄/ tests.sql查詢。 解釋計劃如下。 

root@localhost [world]> EXPLAIN EXTENDED SELECT C.Name as City, Y.Name as Country, L.Language,Y.Population FROM City C INNER JOIN Country Y ON C.CountryCode = Y.Code INNER JOIN CountryLanguage L ON C.CountryCode = L.CountryCode WHERE C.Name LIKE 'D%' AND Y.Continent='Europe' \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: C
type: range
possible_keys: CountryCode,name_key
key: name_key
key_len: 5
ref: NULL
rows: 127
filtered: 100.00
Extra: Using where
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: Y
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 3
ref: world.C.CountryCode
rows: 1
filtered: 100.00
Extra: Using where
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: L
type: ref
possible_keys: PRIMARY,CountryCode
key: CountryCode
key_len: 3
ref: world.C.CountryCode
rows: 2
filtered: 100.00
Extra: Using index
3 rows in set, 1 warning (0.00 sec)

root@localhost [world]> show warnings \G
*************************** 1. row ***************************
Level: Note
Code: 1003
Message: /* select#1 */ select `world`.`C`.`Name` AS `City`,`world`.`Y`.`Name` AS `Country`,`world`.`L`.`Language` AS `Language`,`world`.`Y`.`Population` AS `Population` from `world`.`City` `C` join `world`.`Country` `Y` join `world`.`CountryLanguage` `L` where ((`world`.`Y`.`Code` = `world`.`C`.`CountryCode`) and (`world`.`L`.`CountryCode` = `world`.`C`.`CountryCode`) and (`world`.`Y`.`Continent` = 'Europe') and (`world`.`C`.`Name` like 'D%'))


現在mysqlslap工具,此後一直圍繞的MySQL 5.1.4 
下面是一些其他有用的鏈接。 
現在,我有我的疑問,我可以基準是對數據庫使用以下命令。 

mysqlslap - 並發= 150 - 迭代= 50 - 查詢= / tmp目錄/的test.sql - 創建型模式=世界 

一注: 
查詢具有作為工具方便地做錯誤是非常乾淨的。 
例如下面扔這個錯誤: 

SELECT C.Name as City, Y.Name as Country, L.Language,Y.Population
FROM City C
INNER JOIN Country Y ON C.CountryCode = Y.Code
INNER JOIN CountryLanguage L ON C.CountryCode = L.CountryCode
WHERE C.Name LIKE 'D%' AND Y.Continent='Europe' 

雖然這個查詢工作就好了。 

SELECT C.Name as City, Y.Name as Country, L.Language,Y.Population FROM City C INNER JOIN Country Y ON C.CountryCode = Y.Code INNER JOIN CountryLanguage L ON C.CountryCode = L.CountryCode WHERE C.Name LIKE 'D%' AND Y.Continent='Europe' 


該工具將輸出的基準測試結果為你 


Benchmark
Average number of seconds to run all queries: 0.104 seconds
Minimum number of seconds to run all queries: 0.096 seconds
Maximum number of seconds to run all queries: 0.141 seconds
Number of clients running queries: 150
Average number of queries per client: 1 


mysqlslap - 幫助會給你無數的選擇與測試您的查詢。 

您可以自動做的一切 

# mysqlslap --auto-generate-sql
Benchmark
Average number of seconds to run all queries: 0.243 seconds
Minimum number of seconds to run all queries: 0.243 seconds
Maximum number of seconds to run all queries: 0.243 seconds
Number of clients running queries: 1
Average number of queries per client: 0 


你可以測試插件也是如此。 比如我創建這個表: 

CREATE TABLE `foobar_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time_recorded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB ; 


所以後來用下面的測試。 

# mysqlslap --concurrency=1150 --iterations=530 --query="use test;insert into foobar_table (id) values (null)" --delimiter=";"
mysqlslap: Could not create thread 


確定錯誤是不是非常有幫助......但希望你注意到這個錯誤。 這是很難有1150個並發交易,如果你只有530次迭代。 


# mysqlslap --concurrency=150 --iterations=30 --query=/tmp/test1.sql --create-schema=test --verbose
Benchmark
Average number of seconds to run all queries: 0.260 seconds
Minimum number of seconds to run all queries: 0.192 seconds
Maximum number of seconds to run all queries: 0.476 seconds
Number of clients running queries: 150
Average number of queries per client: 1


例如下面的工作要好得多。 

# mysqlslap --concurrency=200 --iterations=1000 --query=" insert into foobar_table (id) values (null)" --verbose --create-schema=test
Benchmark
Average number of seconds to run all queries: 0.282 seconds
Minimum number of seconds to run all queries: 0.217 seconds
Maximum number of seconds to run all queries: 0.726 seconds
Number of clients running queries: 200
Average number of queries per client: 1 


只是為了證明我們在做真正的插入.. 

root@localhost [test]> select count(id) from foobar_table;
+-----------+
| count(id) |
+-----------+
| 206091 |
+-----------+
1 row in set (0.13 sec) 

現在,我還應該說,這只是我使用博客文章一個測試數據庫,所以不評價對這些結果的生產數據庫。 

我猜點之後這一切......找到一個麻煩的查詢,優化它最好就可以了,它的基準。 這是更好地了解自己的極限,而不是只是一個猜測。 

2013年5月6日星期一

標杆:: MySQL中,CPU,文件I / O,內存:: Sysbench與Apache的基準

Original Post: http://anothermysqldba.blogspot.com/2013/05/benchmarking-mysql-cpu-file-io-memory.html


決定你想用哪一種工具:
我將使用Sysbench的這個例子:
首先下載sysbench
安裝:
SysBench手冊
查看你的選擇:
#sysbench - 測試= OLTP幫助

編譯測試:
FILEIO - 文件I / O測試
CPU - CPU性能測試
內存 - 功能速度測試
線程 - 線程子系統性能測試
互斥 - 互斥性能測試
OLTP - OLTP測試

命令:準備運行清理的幫助版本

下面一些例子:

FILEIO -文件I / O測試
# sysbench --test=fileio help 
fileio options:
--file-num=N number of files to create [128]
--file-block-size=N block size to use in all IO operations [16384]
--file-total-size=SIZE total size of files to create [2G]
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING file operations mode {sync,async,fastmmap,slowmmap} [sync]
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]
--file-fsync-all=[on|off] do fsync() after each write operation [off]
--file-fsync-end=[on|off] do fsync() at the end of test [on]
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
--file-rw-ratio=N reads/writes ratio for combined test [1.5] 

  • #sysbench - 測試= FILEIO準備
  • #sysbench的 - 測試FILEIO - 的文件測試模式= rndwr運行


CPU - CPU性能測試
#sysbench - 測試= CPU幫助
cpu選項:
- CPU的最大素數= N上限為素數發生器[10000] 


  • #sysbench的 - 測試= CPU - NUM線程= 25運行


內存-功能速度測試
# sysbench --test=memory help 
memory options:
--memory-block-size=SIZE size of memory block for test [1K]
--memory-total-size=SIZE total size of data to transfer [100G]
--memory-scope=STRING memory access scope {global,local} [global]
--memory-hugetlb=[on|off] allocate memory from HugeTLB pool [off]
--memory-oper=STRING type of memory operations {read, write, none} [write]
--memory-access-mode=STRING memory access mode {seq,rnd} [seq] 
  • #sysbench - 測試內存<memory選項運行

線程-線程子系統性能測試
# sysbench --test=threads help   
threads options:
--thread-yields=N number of yields to do per request [1000]
--thread-locks=N number of locks per thread [8] 

  • ##sysbench的 - 測試=線程 - NUM線程= 64 - 測試線程 - 線程收益率= 100 - 螺紋鎖= 6運行


互斥-互斥性能測試
# sysbench --test=mutex help   
mutex options:
--mutex-num=N total size of mutex array [4096]
--mutex-locks=N number of mutex locks to do per thread [50000]
--mutex-loops=N number of empty loops to do inside mutex lock [10000] 
  • #sysbench的 - 測試=互斥 - NUM線程= 64運行




OLTP - OLTP測試
# sysbench --test=oltp help
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

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 [] 

sysbench期望找到sbtest數據庫,所以一定要確保和創造,首先定義你喜歡什麼樣的數據庫。
  • sysbench - 測試= OLTP幫助| grep的sbtest
    - OLTP表名= STRING測試表名稱[sbtest]
    - mysql用戶的= STRING MySQL的用戶[sbtest]
    - MYSQL-DB = STRING MySQL數據庫名稱[sbtest]

#sysbench的 - 測試= OLTP - MySQL的主機=本地主機 - MySQL的超級用戶身份 - MySQL的密碼= [<密碼HERE> - mysql的表引擎= InnoDB的準備

#sysbench的mysql的密碼 - 測試= OLTP - MySQL的主機=本地主機 - MySQL的超級用戶身份 - = <password HERE> - mysql的表引擎InnoDB的 - 號線程= 25運行

然後留意你的結果以及數據庫的測試運行。



Apache的基準和| |
WWW ::機械化::火狐

關鍵在這裡帶走的是使用這些工具進行基準測試您的應用程序和過程,不只是一個單一的架構因素。

例如,如果你期望有一個小時20000用戶填寫您的Web表單,那麼你應該基準您的應用程序來處理。 您可以使用上方的工具,模仿的職位只是一個例子,通過令牌,然後測試代碼,在您的應用程序上。 這樣的測試,然後將測試的代碼庫,並與合適的日誌記錄的地方(你也可以打開一個令牌),你可以測試以及開發人員,DBA和系統如何建。

的概念很簡單的例子:

如果你可以打開網址elinks的基準。

elinks http://www.google.com/search?ie=ISO-8859-1\&hl=en\&source=hp\&q=mysql

# ab -n 10 -c 2 http://www.google.com/search?ie=ISO-8859-1\&hl=en\&source=hp\&q=mysql 

當然,你會執行此對您的系統在一個更高的水平,以測試應用程序如何響應。