MySQL基準壓力測試工具MySQLSlap

urgel_babay發表於2016-02-29
2016.2.17

   昨天在新公司新買的阿里雲伺服器上安裝MySQL5.6.25。同事說做一下併發壓力測試,他們開始找一些工具測,但是不熟悉,臨時學又覺得麻煩,所以選擇MySQL自帶的壓力測試工具: mysqlslap 個人感覺還不錯,模式比較多,主要是操作簡單,還有資訊彙總。

mysqlslap是MySQL5.1之後自帶的benchmark基準測試工具,會自動生成schema,載入資料,執行benckmark和查詢資料,語法簡單,靈活,容易使用。該工具可以模擬多個客戶端同時併發的向伺服器發出查詢更新,給出了效能測試資料而且提供了多種引擎的效能比較。mysqlslap為mysql效能最佳化前後提供了直觀的驗證依據。

常用的解釋:
  1. [root@zhanglin ~]# mysqlslap --help
    mysqlslap  Ver 1.0 Distrib 5.1.73, for redhat-linux-gnu (x86_64)
    Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.


    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    Run a query multiple times against the server.
    Usage: mysqlslap [OPTIONS]


    Default options are read from the following files in the given order:
    /etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf 
    The following groups are read: mysqlslap client
    The following options may be given as the first argument:
    --print-defaults        Print the program argument list and exit.
    --no-defaults           Don't read default options from any option file.
    --defaults-file=#       Only read default options from the given file #.
    --defaults-extra-file=# Read this file after the global files are read.
      -?, --help          Display this help and exit.
      -a, --auto-generate-sql 
                          Generate SQL where not supplied by file or command line.     //系統自帶生成的SQL指令碼來測試,非檔案或命令列。
      --auto-generate-sql-add-autoincrement 
                          Add an AUTO_INCREMENT column to auto-generated tables.       //從5.1.18版本開始,?表示對生成的表自動新增auto_increment列。
      --auto-generate-sql-execute-number=# 
                          Set this number to generate a set number of queries to       //設定會話執行SQL語句的次數
                          run.
      --auto-generate-sql-guid-primary 
                          Add GUID based primary keys to auto-generated tables.        //給測試表,根據主鍵新增GUID欄位
      --auto-generate-sql-load-type=name 
                          Specify test load type: mixed, update, write, key, or        //代表要測試的是讀還是寫還是兩者混合的,嗎,預設是混合模式。
                          read; default is mixed.
      --auto-generate-sql-secondary-indexes=# 
                          Number of secondary indexes to add to auto-generated         // 自動增長表除主鍵以外索引的個數。
                          tables.
      --auto-generate-sql-unique-query-number=# 
                          Number of unique queries to generate for automatic tests.    // 自動測試生成的不同查詢的個數。
      --auto-generate-sql-unique-write-number=# 
                          Number of unique queries to generate for                     // 自動測試生成的不同write SQL 語句的個數。
                          auto-generate-sql-write-number.
      --auto-generate-sql-write-number=# 
                          Number of row inserts to perform for each thread (default    //每個執行緒write SQL的數量。
                          is 100).
      --commit=#          Commit records every X number of statements.                 //多少條DML後提交一次。
      -C, --compress      Use compression in server/client protocol.                  // 使用壓縮。
      -c, --concurrency=name 
                          Number of clients to simulate for query to run.          //客戶端併發數量,多個可以用逗號隔開,例如:concurrency=100,500,1000, 併發連線執行緒數分別是100、500、1000個並發。
      --create=name       File or string to use create tables.                        //表名,可以直接指定名字也可指定到某個檔案。
      --create-schema=name 
                          Schema to run tests in.                                     //用什麼使用者測試。
      --csv[=name]        Generate CSV output to named file or to stdout if no file     //以CSV 檔案輸出測試結果。
                          is named.
      -#, --debug[=#]     This is a non-debug version. Catch this and exit.
      --debug-check       Check memory and open file usage at exit.                   //檢查CPU以及記憶體的相關資訊。
      -T, --debug-info    Print some debug info at exit.                              //結束時 列印debug資訊。
      -F, --delimiter=name 
                          Delimiter to use in SQL statements supplied in file or
                          command line.
      --detach=#          Detach (close and reopen) connections after X number of
                          requests.
      -e, --engine=name   Storage engine to use for creating the table.               //需要測試的儲存引擎。
      -h, --host=name     Connect to host.                                            //需要測試的資料庫主機。
      -i, --iterations=#  Number of times to run the tests.                           //-i N 測試執行的次數,代表要在不同併發環境下,各自執行測試多少次。
      --no-drop           Do not drop the schema after the test.                      //測試結束,保留測試使用者資料。
      -x, --number-char-cols=name                                                     //建立測試表的 varchar 型欄位數量,預設是1。
                          Number of VARCHAR columns to create in table if
                          specifying --auto-generate-sql.
      -y, --number-int-cols=name                                                      //建立測試表的 int 型欄位數量,預設是1.
                          Number of INT columns to create in table if specifying
                          --auto-generate-sql.
      --number-of-queries=# 
                          Limit each client to this number of queries (this is not     //每個客戶端 總的執行SQL次數(併發客戶數×每客戶查詢次數)。
                          exact).
      --only-print        Do not connect to the databases, but instead print out       //只列印測試語句而不實際執行。類似日常檢視執行計劃
                          what would have been done.
      -p, --password[=name] 
                          Password to use when connecting to server. If password is     //連結MySQL資料庫使用者的登入密碼。
                          not given it's asked from the tty. 
      -P, --port=#        Port number to use for connection.                            //埠號。
      --post-query=name   Query to run or file containing query to execute after        //測試後  執行的SQL語句
                          tests have completed.
      --post-system=name  system() string to execute after tests have completed.        //測試後  執行的作業系統語句
      --pre-query=name    Query to run or file containing query to execute before       //測試前  執行的SQL語句
                          running tests.
      --pre-system=name   system() string to execute before running tests.              //測試前  執行的作業系統語句
      --protocol=name     The protocol to use for connection (tcp, socket, pipe,        // 連結伺服器使用的 連結協議
                          memory).
      -q, --query=name    Query to run or file containing query to run.                 //測試的SQL語句 一般是自主設計的SQL
      -s, --silent        Run program in silent mode - no output.                       //不顯示測試
      -S, --socket=name   The socket file to use for connection.                        //連線伺服器的socket通道檔案
      --ssl               Enable SSL for connection (automatically enabled with
                          other flags).Disable with --skip-ssl.
      --ssl-ca=name       CA file in PEM format (check OpenSSL docs, implies
                          --ssl).
      --ssl-capath=name   CA directory (check OpenSSL docs, implies --ssl).
      --ssl-cert=name     X509 cert in PEM format (implies --ssl).
      --ssl-cipher=name   SSL cipher to use (implies --ssl).
      --ssl-key=name      X509 key in PEM format (implies --ssl).
      --ssl-verify-server-cert 
                          Verify server's "Common Name" in its cert against
                          hostname used when connecting. This option is disabled by
                          default.
      -u, --user=name     User for login if not current user.                           // 登入MySQL使用者,
      -v, --verbose       More verbose output; you can use this multiple times to       //更詳細的輸出。
                          get even more verbose output.
      -V, --version       Output version information and exit.                          //版本資訊




測試命令:
mysqlslap -uroot -pzhanglin --concurrency=1000 --iterations=10 --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement --engine=myisam --number-of-queries=10 --debug-info
  #備註本次測試以1000個併發執行緒、測試10次,自動生成SQL測試指令碼、讀、寫、更新混合測試、自增長欄位、測試引擎為myisam、共執行10次查詢,輸出cpu資源資訊

mysqlslap --concurrency=10,200,1000 --iterations=20 --number-int-cols=8 --number-char-cols=30 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=read --engine=myisam,innodb --number-of-queries=5000 --verbose --socket=/tmp/mysql/mysql.sock -uroot -pzhanglin
   #系統指令碼測試,增加int型 8列char 型30列,測試2種引擎myisam,innodb讀的效能,分別用10,200,1000個客戶端對伺服器進行測試總共5000個查詢語句 執行20次查詢



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30936525/viewspace-2016530/,如需轉載,請註明出處,否則將追究法律責任。

相關文章