最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL壓力測試方法 如何使用mysqlslap測試MySQL的壓力?

 更新時(shí)間:2016年05月13日 15:53:45   投稿:mdxy-dxy  
生產(chǎn)服務(wù)器用LANMP組合和用LAMP組合有段時(shí)間了,總體來說都很穩(wěn)定。但出現(xiàn)過幾次因?yàn)镸YSQL并發(fā)太多而掛掉,一直想對(duì)MYSQL做壓力測試。剛看到一篇介紹MYSQL壓力測試的文章,確實(shí)不錯(cuò),先收藏先吧

其實(shí)mysql測試也沒有這么復(fù)雜,除了一些常用的select\insert\update\deletc這些外,其實(shí)測試他的并發(fā)量才是最重要的。比如在連接數(shù)1K的時(shí)候,并發(fā)量能否滿足當(dāng)前請(qǐng)求\服務(wù)器性能、內(nèi)存CPU使用情況。說白了,測試mysql就是測試他的配置文件和并發(fā)量及服務(wù)器性能。

一、工具
首選工具mysql自帶的:mysqlslap

–auto-generate-sql, -a
自動(dòng)生成測試表和數(shù)據(jù)

–auto-generate-sql-load-type=type
測試語句的類型。取值包括:read,key,write,update和mixed(默認(rèn))。

–number-char-cols=N, -x N
自動(dòng)生成的測試表中包含多少個(gè)字符類型的列,默認(rèn)1

–number-int-cols=N, -y N
自動(dòng)生成的測試表中包含多少個(gè)數(shù)字類型的列,默認(rèn)1

–number-of-queries=N
總的測試查詢次數(shù)(并發(fā)客戶數(shù)×每客戶查詢次數(shù))

–query=name,-q
使用自定義腳本執(zhí)行測試,例如可以調(diào)用自定義的一個(gè)存儲(chǔ)過程或者sql語句來執(zhí)行測試。

–create-schema
測試的schema,MySQL中schema也就是database

–commint=N
多少條DML后提交一次

–compress, -C
如果服務(wù)器和客戶端支持都?jí)嚎s,則壓縮信息傳遞

–concurrency=N, -c N
并發(fā)量,也就是模擬多少個(gè)客戶端同時(shí)執(zhí)行select??芍付ǘ鄠€(gè)值,以逗號(hào)或者–delimiter參數(shù)指定的值做為分隔符

–engine=engine_name, -e engine_name
創(chuàng)建測試表所使用的存儲(chǔ)引擎,可指定多個(gè)

–iterations=N, -i N
測試執(zhí)行的迭代次數(shù)

–detach=N
執(zhí)行N條語句后斷開重連

–debug-info, -T
打印內(nèi)存和CPU的信息

–only-print
只打印測試語句而不實(shí)際執(zhí)行

———————————————————————————————-
測試的過程需要生成測試表,插入測試數(shù)據(jù),這個(gè)mysqlslap可以自動(dòng)生成,默認(rèn)生成一個(gè)mysqlslap的schema,如果已經(jīng)存在則先刪除,這里要注意了,不要用–create-schema指定已經(jīng)存在的庫,否則后果可能很嚴(yán)重??梢杂猫Conly-print來打印實(shí)際的測試過程:

# mysqlslap -a –only-print

DROP SCHEMA IF EXISTS `mysqlslap`;
 CREATE SCHEMA `mysqlslap`;
 use mysqlslap;
 CREATE TABLE `t1` (intcol1 INT(32) ,charcol1 VARCHAR(128));
 INSERT INTO t1 VALUES (1804289383,'mxvtvmC9127qJNm06sGB8R92q2j7vTiiITRD9rdxBL');
 …
 SELECT intcol1,charcol1 FROM t1;
 INSERT INTO t1 VALUES (364531492,'qMa5SuKo4M5OM7ldvisSc6WK9rsNTGFxkDJ4EAwW');
 DROP SCHEMA IF EXISTS `mysqlslap`;

可以看到最后由刪除一開始創(chuàng)建的schema的動(dòng)作,整個(gè)測試完成后不會(huì)在數(shù)據(jù)庫中留下痕跡。假如我們執(zhí)行一次測試,分別50和100個(gè)并發(fā),執(zhí)行1000次總查詢,那么:

# mysqlslap -uroot -p123456 -a –concurrency=50,100 –number-of-queries 1000 –debug-info

Benchmark
Average number of seconds to run all queries: 0.375 seconds
Minimum number of seconds to run all queries: 0.375 seconds
Maximum number of seconds to run all queries: 0.375 seconds
Number of clients running queries: 50
Average number of queries per client: 20

Benchmark
Average number of seconds to run all queries: 0.453 seconds
Minimum number of seconds to run all queries: 0.453 seconds
Maximum number of seconds to run all queries: 0.453 seconds
Number of clients running queries: 100
Average number of queries per client: 10

User time 0.29, System time 0.11
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 4032, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 7319, Involuntary context switches 681

以上結(jié)果可以看出,50和100個(gè)并發(fā)分別得到一次測試結(jié)果(Benchmark),并發(fā)數(shù)越多,執(zhí)行完所有查詢的時(shí)間越長。為了準(zhǔn)確起見,可以多迭代測試幾次:

# mysqlslap -a –concurrency=50,100 –number-of-queries 1000 –iterations=5 –debug-info

Benchmark
Average number of seconds to run all queries: 0.380 seconds
Minimum number of seconds to run all queries: 0.377 seconds
Maximum number of seconds to run all queries: 0.385 seconds
Number of clients running queries: 50
Average number of queries per client: 20

Benchmark
Average number of seconds to run all queries: 0.447 seconds
Minimum number of seconds to run all queries: 0.444 seconds
Maximum number of seconds to run all queries: 0.451 seconds
Number of clients running queries: 100
Average number of queries per client: 10

User time 1.44, System time 0.67
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 17922, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 36796, Involuntary context switches 4093

測試同時(shí)不同的存儲(chǔ)引擎的性能進(jìn)行對(duì)比:
# mysqlslap -uroot -p123456 -a -concurrency=50,100 –number-of-queries 1000 –iterations=5 –engine=myisam,innodb –debug-info
Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.200 seconds
Minimum number of seconds to run all queries: 0.188 seconds
Maximum number of seconds to run all queries: 0.210 seconds
Number of clients running queries: 50
Average number of queries per client: 20

Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.238 seconds
Minimum number of seconds to run all queries: 0.228 seconds
Maximum number of seconds to run all queries: 0.251 seconds
Number of clients running queries: 100
Average number of queries per client: 10

Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.375 seconds
Minimum number of seconds to run all queries: 0.370 seconds
Maximum number of seconds to run all queries: 0.379 seconds
Number of clients running queries: 50
Average number of queries per client: 20

Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.443 seconds
Minimum number of seconds to run all queries: 0.440 seconds
Maximum number of seconds to run all queries: 0.447 seconds
Number of clients running queries: 100
Average number of queries per client: 10

User time 2.83, System time 1.66
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 34692, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 87306, Involuntary context switches 10326

# mysqladmin -uroot -p123456 -i 10 extended status 每10秒刷新一次

Aborted_connects 嘗試已經(jīng)失敗的MySQL服務(wù)器的連接的次數(shù)。
Connections 試圖連接MySQL服務(wù)器的次數(shù)。
Created_tmp_tables 當(dāng)執(zhí)行語句時(shí),已經(jīng)被創(chuàng)造了的隱含臨時(shí)表的數(shù)量。
Delayed_insert_threads 正在使用的延遲插入處理器線程的數(shù)量。
Delayed_writes 用INSERT DELAYED寫入的行數(shù)。
Delayed_errors 用INSERT DELAYED寫入的發(fā)生某些錯(cuò)誤(可能重復(fù)鍵值)的行數(shù)。
Flush_commands 執(zhí)行FLUSH命令的次數(shù)。
Handler_delete 請(qǐng)求從一張表中刪除行的次數(shù)。
Handler_read_first 請(qǐng)求讀入表中第一行的次數(shù)。
Handler_read_key 請(qǐng)求數(shù)字基于鍵讀行。
Handler_read_next 請(qǐng)求讀入基于一個(gè)鍵的一行的次數(shù)。
Handler_read_rnd 請(qǐng)求讀入基于一個(gè)固定位置的一行的次數(shù)。
Handler_update 請(qǐng)求更新表中一行的次數(shù)。
Handler_write 請(qǐng)求向表中插入一行的次數(shù)。
Key_blocks_used 用于關(guān)鍵字緩存的塊的數(shù)量。
Key_read_requests 請(qǐng)求從緩存讀入一個(gè)鍵值的次數(shù)。
Key_reads 從磁盤物理讀入一個(gè)鍵值的次數(shù)。
Key_write_requests 請(qǐng)求將一個(gè)關(guān)鍵字塊寫入緩存次數(shù)。
Key_writes 將一個(gè)鍵值塊物理寫入磁盤的次數(shù)。
Max_used_connections 同時(shí)使用的連接的最大數(shù)目。
Not_flushed_key_blocks 在鍵緩存中已經(jīng)改變但是還沒被清空到磁盤上的鍵塊。
Not_flushed_delayed_rows 在INSERT DELAY隊(duì)列中等待寫入的行的數(shù)量。
Open_tables 打開表的數(shù)量。
Open_files 打開文件的數(shù)量。
Open_streams 打開流的數(shù)量(主要用于日志記載)
Opened_tables 已經(jīng)打開的表的數(shù)量。
Questions 發(fā)往服務(wù)器的查詢的數(shù)量。
Slow_queries 要花超過long_query_time時(shí)間的查詢數(shù)量。
Threads_connected 當(dāng)前打開的連接的數(shù)量。
Threads_running 不在睡眠的線程數(shù)量。
Uptime 服務(wù)器工作了多少秒。

相關(guān)文章

  • mysql?or走索引加索引及慢查詢的作用

    mysql?or走索引加索引及慢查詢的作用

    這篇文章主要介紹了mysql?or走索引加索引及慢查詢的作用,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • Mac安裝 mysql 數(shù)據(jù)庫總結(jié)

    Mac安裝 mysql 數(shù)據(jù)庫總結(jié)

    本文給大家分享的是如何在Mac下安裝mysql數(shù)據(jù)庫的方法,總結(jié)的很全面,有需要的小伙伴可以參考下
    2016-04-04
  • 詳解MySQL從入門到放棄-安裝

    詳解MySQL從入門到放棄-安裝

    這篇文章主要介紹了MySQL從入門到放棄-安裝,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • mysql向mariadb平滑過渡的步驟詳解

    mysql向mariadb平滑過渡的步驟詳解

    MySQL之父Widenius先生離開了Sun之后,覺得依靠Sun/Oracle來發(fā)展MySQL,實(shí)在很不靠譜,于是決定從新開發(fā)代碼全部開源免費(fèi)關(guān)系型數(shù)據(jù)庫,這就是MariaDB。下面這篇文章主要給大家介紹了關(guān)于mysql向mariadb平滑過渡的相關(guān)資料,需要的朋友可以參考下。
    2017-12-12
  • MySQL修改表結(jié)構(gòu)操作命令總結(jié)

    MySQL修改表結(jié)構(gòu)操作命令總結(jié)

    這篇文章主要介紹了MySQL修改表結(jié)構(gòu)操作命令總結(jié),包含如刪除列、添加列、修改列、添加主鍵、刪除主鍵、添加唯一索引、添加普通索引等內(nèi)容,需要的朋友可以參考下
    2014-12-12
  • Mysql中的select ...for update

    Mysql中的select ...for update

    這篇文章主要介紹了Mysql中的select ...for update用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • 利用mysql事務(wù)特性實(shí)現(xiàn)并發(fā)安全的自增ID示例

    利用mysql事務(wù)特性實(shí)現(xiàn)并發(fā)安全的自增ID示例

    項(xiàng)目中經(jīng)常會(huì)用到自增id,比如uid,下面為大家介紹下利用mysql事務(wù)特性實(shí)現(xiàn)并發(fā)安全的自增ID,感興趣的朋友可以參考下
    2013-11-11
  • MySQL中常見的八種SQL錯(cuò)誤用法示例

    MySQL中常見的八種SQL錯(cuò)誤用法示例

    這篇文章主要給大家介紹了關(guān)于MySQL中常見的八種SQL錯(cuò)誤用法示例的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • MySQL如何計(jì)算連續(xù)登錄天數(shù)

    MySQL如何計(jì)算連續(xù)登錄天數(shù)

    這篇文章主要介紹了MySQL如何計(jì)算連續(xù)登錄天數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • 磁盤寫滿導(dǎo)致MySQL復(fù)制失敗的解決方案

    磁盤寫滿導(dǎo)致MySQL復(fù)制失敗的解決方案

    這篇文章主要介紹了磁盤寫滿導(dǎo)致MySQL復(fù)制失敗的解決方案,幫助大家更好的理解和學(xué)習(xí)使用MySQL,感興趣的朋友可以了解下
    2021-04-04

最新評(píng)論

会理县| 玛曲县| 历史| 海阳市| 时尚| 旅游| 仙居县| 噶尔县| 隆子县| 沐川县| 芦山县| 灵寿县| 托克逊县| 平乐县| 高陵县| 沂源县| 扎囊县| 邢台市| 南汇区| 灵川县| 涡阳县| 固镇县| 扎鲁特旗| 五华县| 兴文县| 安塞县| 卢氏县| 上犹县| 台山市| 莫力| 白银市| 莱州市| 忻城县| 陇南市| 和静县| 泸西县| 从化市| 观塘区| 灵璧县| 台南县| 历史|