成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

MySQL高性能學(xué)習(xí)筆記

數(shù)據(jù)庫 MySQL
sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,可以用來進(jìn)行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫的性能測試。目前支持的數(shù)據(jù)庫有MySQL、Oracle和PostgreSQL。

一、Ubuntu 安裝mysql

我們在Ubuntu環(huán)境下裝一個測試用的MySQL來學(xué)習(xí)。

1.更新包

  1. sudo apt-get update 

2.安裝MySQL的服務(wù)端和客戶端

  1. sudo apt-get install mysql-server mysql-client 

在安裝的過程中,需要輸入數(shù)據(jù)庫密碼。

3.啟動Mysql

  1. sudo service mysql restart 

4.登錄mysql

  1. mysql -u root -p 

二、sysbench基準(zhǔn)測試

sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,可以用來進(jìn)行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫的性能測試。目前支持的數(shù)據(jù)庫有MySQL、Oracle和PostgreSQL。當(dāng)前功能允許測試的系統(tǒng)參數(shù)有:

file I/O performance (文件I / O性能)

scheduler performance (調(diào)度性能)

memory allocation and transfer speed (內(nèi)存分配和傳輸速度)

POSIX threads implementation performance (POSIX線程執(zhí)行績效)

database server performance (OLTP benchmark) (數(shù)據(jù)庫服務(wù)器性能)

1.安裝

Ubuntu系統(tǒng)可以直接apt,如:

  1. apt-get install sysbench 

在安裝的時候出現(xiàn)了這樣的錯誤:Could not get lock /var/lib/dpkg/lock

出現(xiàn)這個問題可能是有另外一個程序正在運行,導(dǎo)致資源被鎖不可用。而導(dǎo)致資源被鎖的原因可能是上次運行安裝或更新時沒有正常完成,進(jìn)而出現(xiàn)此狀況,解決的辦法其實很簡單:

在終端中敲入以下兩句

  1. sudo rm /var/cache/apt/archives/lock 
  2.  
  3. sudo rm /var/lib/dpkg/lock 

 

再試著安裝,問題解決。

2.通用選項說明

  1. root@db2:~# sysbench 
  2.  
  3. Missing required command argument. 

 

Usage: #使用方法

  1. sysbench [general-options]... --test=<test-name> [test-options]... command 

General options: #通用選項

--num-threads=N number of threads to use [1] #創(chuàng)建測試線程的數(shù)目。默認(rèn)為1.

--max-requests=N limit for total number of requests [10000] #請求的最大數(shù)目。默認(rèn)為10000,0代表不限制。

--max-time=N limit for total execution time in seconds [0] #最大執(zhí)行時間,單位是s。默認(rèn)是0,不限制。

--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] #超過max-time強(qiáng)制中斷。默認(rèn)是off。

--thread-stack-size=SIZE size of stack per thread [32K] #每個線程的堆棧大小。默認(rèn)是32K。

--init-rng=[on|off] initialize random number generator [off] #在測試開始時是否初始化隨機(jī)數(shù)發(fā)生器。默認(rèn)是off。

--test=STRING test to run #指定測試項目名稱。

--debug=[on|off] print more debugging info [off] #是否顯示更多的調(diào)試信息。默認(rèn)是off。

--validate=[on|off] perform validation checks where possible [off] #在可能情況下執(zhí)行驗證檢查。默認(rèn)是off。

--help=[on|off] print help and exit #幫助信息。

--version=[on|off] print version and exit #版本信息。

Compiled-in tests: #測試項目

fileio - File I/O test #IO

cpu - CPU performance test #CPU

memory - Memory functions speed test #內(nèi)存

threads - Threads subsystem performance test #線程

mutex - Mutex performance test #互斥性能測試

oltp - OLTP test # 數(shù)據(jù)庫,事務(wù)處理

Commands: prepare:測試前準(zhǔn)備工作; run:正式測試 cleanup:測試后刪掉測試數(shù)據(jù) help version

See 'sysbench --test=<name> help' for a list of options for each test. #查看每個測試項目的更多選項列表

更多選項:

1):sysbench --test=fileio help

  1. root@db2:~# sysbench --test=fileio help 
  2.  
  3. sysbench 0.4.12: multi-threaded system evaluation benchmark 

 

fileio options:

--file-num=N 創(chuàng)建測試文件的數(shù)量。默認(rèn)是128

--file-block-size=N 測試時文件塊的大小。默認(rèn)是16384(16K)

--file-total-size=SIZE 測試文件的總大小。默認(rèn)是2G

--file-test-mode=STRING 文件測試模式{seqwr(順序?qū)?, seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機(jī)讀), rndwr(隨機(jī)寫), rndrw(隨機(jī)讀寫)}

--file-io-mode=STRING 文件操作模式{sync(同步),async(異步),fastmmap(快速map映射),slowmmap(慢map映射)}。默認(rèn)是sync

--file-extra-flags=STRING 使用額外的標(biāo)志來打開文件{sync,dsync,direct} 。默認(rèn)為空

--file-fsync-freq=N 執(zhí)行fsync()的頻率。(0 – 不使用fsync())。默認(rèn)是100

--file-fsync-all=[on|off] 每執(zhí)行完一次寫操作就執(zhí)行一次fsync。默認(rèn)是off

--file-fsync-end=[on|off] 在測試結(jié)束時才執(zhí)行fsync。默認(rèn)是on

--file-fsync-mode=STRING 使用哪種方法進(jìn)行同步{fsync, fdatasync}。默認(rèn)是fsync

--file-merged-requests=N 如果可以,合并最多的IO請求數(shù)(0 – 表示不合并)。默認(rèn)是0

--file-rw-ratio=N 測試時的讀寫比例。默認(rèn)是1.5

2):sysbench --test=cpu help

--cpu-max-prime=N 最大質(zhì)數(shù)發(fā)生器數(shù)量。默認(rèn)是10000

3):sysbench --test=memory help

  1. root@db2:~# sysbench --test=memory help 
  2.  
  3. sysbench 0.4.12: multi-threaded system evaluation benchmark 

 

memory options:

--memory-block-size=SIZE 測試時內(nèi)存塊大小。默認(rèn)是1K

--memory-total-size=SIZE 傳輸數(shù)據(jù)的總大小。默認(rèn)是100G

--memory-scope=STRING 內(nèi)存訪問范圍{global,local}。默認(rèn)是global

--memory-hugetlb=[on|off] 從HugeTLB池內(nèi)存分配。默認(rèn)是off

--memory-oper=STRING 內(nèi)存操作類型。{read, write, none} 默認(rèn)是write

--memory-access-mode=STRING存儲器存取方式{seq,rnd} 默認(rèn)是seq

4):sysbench --test=threads help

sysbench 0.4.12: multi-threaded system evaluation benchmark

threads options:

--thread-yields=N 每個請求產(chǎn)生多少個線程。默認(rèn)是1000

--thread-locks=N 每個線程的鎖的數(shù)量。默認(rèn)是8

5):sysbench --test=mutex help

  1. root@db2:~# sysbench --test=mutex help 
  2.  
  3. sysbench 0.4.12: multi-threaded system evaluation benchmark 

 

mutex options:

--mutex-num=N 數(shù)組互斥的總大小。默認(rèn)是4096

--mutex-locks=N 每個線程互斥鎖的數(shù)量。默認(rèn)是50000

--mutex-loops=N 內(nèi)部互斥鎖的空循環(huán)數(shù)量。默認(rèn)是10000

6): sysbench --test=oltp help

  1. root@db2:~# sysbench --test=oltp help 
  2.  
  3. sysbench 0.4.12: multi-threaded system evaluation benchmark 

 

oltp options:

--oltp-test-mode=STRING 執(zhí)行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默認(rèn)是complex

--oltp-reconnect-mode=STRING 重新連接模式{session(不使用重新連接。每個線程斷開只在測試結(jié)束),transaction(在每次事務(wù)結(jié)束后重新連接),query(在每個SQL語句執(zhí)行完重新連接),random(對于每個事務(wù)隨機(jī)選擇以上重新連接模式)}。默認(rèn)是session

--oltp-sp-name=STRING 存儲過程的名稱。默認(rèn)為空

--oltp-read-only=[on|off] 只讀模式。Update,delete,insert語句不可執(zhí)行。默認(rèn)是off

--oltp-skip-trx=[on|off] 省略begin/commit語句。默認(rèn)是off

--oltp-range-size=N 查詢范圍。默認(rèn)是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 查詢類型對于非事務(wù)執(zhí)行模式{select, update_key, update_nokey, insert, delete} [select]

--oltp-auto-inc=[on|off] AUTO_INCREMENT是否開啟。默認(rèn)是on

--oltp-connect-delay=N 在多少微秒后連接數(shù)據(jù)庫。默認(rèn)是10000

--oltp-user-delay-min=N 每個請求最短等待時間。單位是ms。默認(rèn)是0

--oltp-user-delay-max=N 每個請求最長等待時間。單位是ms。默認(rèn)是0

--oltp-table-name=STRING 測試時使用到的表名。默認(rèn)是sbtest

--oltp-table-size=N 測試表的記錄數(shù)。默認(rèn)是10000

--oltp-dist-type=STRING 分布的隨機(jī)數(shù){uniform(均勻分布),Gaussian(高斯分布),special(空間分布)}。默認(rèn)是special

--oltp-dist-iter=N 產(chǎn)生數(shù)的迭代次數(shù)。默認(rèn)是12

--oltp-dist-pct=N 值的百分比被視為'special' (for special distribution)。默認(rèn)是1

--oltp-dist-res=N ‘special’的百分比值。默認(rèn)是75

General database options:

--db-driver=STRING 指定數(shù)據(jù)庫驅(qū)動程序('help' to get list of available drivers)

--db-ps-mode=STRING編制報表使用模式{auto, disable} [auto]

Compiled-in database drivers:

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

3.測試線程

  1. sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run 

4.測試IO

--num-threads 開啟的線程 --file-total-size 總的文件大小

1,prepare階段,生成需要的測試文件,完成后會在當(dāng)前目錄下生成很多小文件。

  1. sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare 

2,run階段

  1. sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run 

下面的命令運行文件 I/O 混合隨機(jī)讀/寫基準(zhǔn)測試:

 

  1. sysbench --test=fileio --file-total-size=3G --file-test-mode=rndrw --max-time=300 --max-requests=0 run 

 

 

 

執(zhí)行結(jié)果:

 

輸出結(jié)果分析:

每秒請求數(shù)是:233.33 Requests/sec

吞吐量是:3.6458Mb/sec

清除運行文件:

  1. sysbench --test=fileio --file-total-size=3G cleanup 

5.清理測試時生成的文件

  1. sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup 

6.測試內(nèi)存

  1. sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run 

7.測試mutex

  1. sysbench –test=mutex –num-threads=100 –mutex-num=1000 –mutex-locks=100000 –mutex-loops=10000 run 

8.測試OLTP

1,prepare階段,生成需要的測試表

  1. sysbench --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.X.X --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123456 prepare 

2,run階段

  1. sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123456 run 

3,清理測試時生成的測試表

  1. sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123456 cleanup 

三、服務(wù)器性能剖析

我們實際開發(fā)中,最常碰到三個性能相關(guān)的服務(wù)器請求:

1、如何確認(rèn)服務(wù)器是否達(dá)到了性能最佳的狀態(tài);

2、找出某條語句為什么執(zhí)行不夠快

3、診斷被用戶描述成“停頓”、“堆積”或“卡死”的某些間歇性疑難故障

找到慢的原因,我們才能夠?qū)ΠY下藥。

1、何為性能?

我們將性能定義為完成某件任務(wù)所需要的時間度量,換句話說,性能即響應(yīng)時間。

完成一項任務(wù)所需要的時間可以分成兩部分:執(zhí)行時間和等待時間。

2、測量PHP應(yīng)用程序

這里我們用一個PHP性能剖析工具,名叫ifP(instrumentation-for-php),代碼托管在Google Code上(https://code.google.com/archi...),該工具可以更好的關(guān)注數(shù)據(jù)庫的調(diào)用。所以當(dāng)無法在數(shù)據(jù)庫層面進(jìn)行測試的時候,Ifp可以很好的幫助應(yīng)用剖析數(shù)據(jù)庫的利用率。Ifp是一個提供了計數(shù)器和計時器的單例類,很容易部署到生產(chǎn)環(huán)境中,因為不需要訪問PHP的配置權(quán)限(因為對于很多開發(fā)人員來說,都沒有訪問PHP的配置的權(quán)限。)

  1. error_reporting(-1); 
  2. require_once('../src/Instrumentation.php'); 
  3.  
  4. $instance = false
  5. $ret      = Instrumentation::get_instance()->start_request(); 
  6. print_r($ret); 

 

責(zé)任編輯:龐桂玉 來源: segmentfault
相關(guān)推薦

2024-12-24 10:50:05

GinWeb開發(fā)

2025-03-04 08:00:00

機(jī)器學(xué)習(xí)Rust開發(fā)

2018-03-30 18:17:10

MySQLLinux

2019-07-12 08:49:04

MySQ數(shù)據(jù)庫Redis

2018-05-08 18:26:49

數(shù)據(jù)庫MySQL性能

2019-03-01 11:03:22

Lustre高性能計算

2018-09-18 17:20:14

MySQL優(yōu)化數(shù)據(jù)庫

2021-03-18 08:53:44

MySQL數(shù)據(jù)庫索引

2017-07-07 16:36:28

BIOIO模型 NIO

2025-05-06 01:00:00

Excel高性能內(nèi)存

2022-03-21 14:13:22

Go語言編程

2020-07-16 08:06:53

網(wǎng)關(guān)高性能

2023-09-22 11:48:37

2024-12-25 14:03:03

2020-01-07 16:16:57

Kafka開源消息系統(tǒng)

2024-04-25 10:09:02

2017-11-28 17:14:16

華為云

2018-06-22 13:45:08

數(shù)據(jù)庫MySQLtable-cache

2009-03-01 22:23:39

LinuxKernelLinuxDNA

2011-02-23 12:59:08

JSJavaScript瀏覽器
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 成人免费视频在线观看 | 国产黄色网址在线观看 | 中文字幕第一页在线 | 精品中文字幕视频 | 久久久蜜桃一区二区人 | 国产a区| 欧美精品99 | 风间由美一区二区三区在线观看 | 亚洲欧美日韩中文字幕一区二区三区 | 99精品一区二区 | 97国产超碰 | 超碰在线国产 | 国产午夜精品福利 | 日本在线视频中文字幕 | 一区在线视频 | 春色av| 亚洲国产一区二区三区 | 九九热久久免费视频 | 国产情侣在线看 | 日韩精品一区中文字幕 | 国产一区二区三区视频 | 国产精品一区在线 | 亚洲网站在线 | 午夜精品一区二区三区在线视频 | 国产精品成人久久久久 | 欧美一区二区三区在线观看 | 久久精品一区二区视频 | 亚洲国产成人精品一区二区 | 日韩精品视频在线播放 | 美国十次成人欧美色导视频 | 天天干天天干 | 国产在线视频一区 | 欧美一区二区激情三区 | 波多野结衣一区二区 | a免费视频 | 久久久www成人免费无遮挡大片 | 韩日视频在线观看 | 亚洲视频一区在线 | 免费一区二区三区 | 久久视频精品 | 久久久久久精 |