<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 1.理論知識: ### 1.1 定義 > 1. 基準測試是一種測量和評估軟件性能指標的活動,用于建立某個時刻的性能基準,以便當系統發生軟硬件變化時重新進行基準測試以評估變化對性能的影響 > 2. 基準測試是針對系統設置的一種壓力測試,但是和壓力測試還是有區別的 > 基準測試:直接、簡單,易于比較,用于評估服務器的處理能力 > 基準測試:可能不關心業務邏輯,所使用的查詢和業務的真實性可以和業務環境沒有關系 > 壓力測試:對真實的業務數據進行測試,獲得真實系統所能承受的壓力 > 壓力測試:需要針對不同的應用場景,所使用的數據和查詢也是真實用到的 ### 1.2 測試步驟 選擇sysbench為測試工具 1.安裝sysbench 1)下載安裝包 `wget https://github.com/akopytov/sysbench/archive/0.5.zip` 2)安裝依賴工具 ~~~ apt -y install make automake libtool pkg-config libaio-dev vim-common # For MySQL support apt -y install libmysqlclient-dev # For PostgreSQL support apt -y install libpq-dev ~~~ 3)編譯安裝 ~~~ unzip 0.5.zip cd sysbench-0.5 ./autogen.sh # Add --with-pgsql to build with PostgreSQL support ./configure make make install ~~~ 2. 準備測試 1) 創建測試庫 ~~~ create database sysbenchtest; ~~~ 2) 創建測試用戶 ~~~ grant all privileges on sysbenchtest.* to sysbench@'localhost' identified by '4rfv$RFV'; flush privileges; ~~~ 3) 準備測試數據:構建5張表,每張表10萬條數據 ~~~ sysbench --test=./sysbench/tests/db/oltp.lua --mysql-host=127.0.0.1 --mysql-db=sysbenchtest --mysql-user=sysbench \ --mysql-password='4rfv$RFV' --oltp-test-mode=complex --oltp-tables-count=5 --oltp-table-size=100000 --threads=10 --time=120 \ --rand-init=on --report-interval=10 --mysql-table-engine=innodb prepare ~~~ * 參數說明 ~~~ mysql-db=dbtest1a:測試使用的目標數據庫,這個庫名要事先創建 --oltp-tables-count=10:產生表的數量 --oltp-table-size=500000:每個表產生的記錄行數 --oltp-dist-type=uniform:指定隨機取樣類型,可選值有 uniform(均勻分布), Gaussian(高斯分布), special(空間分布)。默認是special --oltp-read-only=off:表示不止產生只讀SQL,也就是使用oltp.lua時會采用讀寫混合模式。默認 off,如果設置為on,則不會產生update,delete,insert的sql。 --oltp-test-mode=nontrx:執行模式,這里是非事務式的。可選值有simple,complex,nontrx。默認是complex simple:簡單查詢,SELECT c FROM sbtest WHERE id=N complex (advanced transactional):事務模式在開始和結束事務之前加上begin和commit, 一個事務里可以有多個語句,如點查詢、范圍查詢、排序查詢、更新、刪除、插入等,并且為了不破壞測試表的數據,該模式下一條記錄刪除后會在同一個事務里添加一條相同的記錄。 nontrx (non-transactional):與simple相似,但是可以進行update/insert等操作,所以如果做連續的對比壓測,你可能需要重新cleanup,prepare。 --oltp-skip-trx=[on|off]:省略begin/commit語句。默認是off --rand-init=on:是否隨機初始化數據,如果不隨機化那么初始好的數據每行內容除了主鍵不同外其他完全相同 --num-threads=12: 并發線程數,可以理解為模擬的客戶端并發連接數 --report-interval=10:表示每10s輸出一次測試進度報告 --max-requests=0:壓力測試產生請求的總數,如果以下面的max-time來記,這個值設為0 --max-time=120:壓力測試的持續時間,這里是2分鐘。 注意,針對不同的選項取值就會有不同的子選項。比如oltp-dist-type=special,就有比如oltp-dist-pct=1、oltp-dist-res=50兩個子選項,代表有50%的查詢落在1%的行(即熱點數據)上,另外50%均勻的(sample uniformly)落在另外99%的記錄行上。 再比如oltp-test-mode=nontrx時, 就可以有oltp-nontrx-mode,可選值有select(默認), update_key, update_nokey, insert, delete,代表非事務式模式下使用的測試sql類型。 以上代表的是一個只讀的例子,可以把num-threads依次遞增(16,36,72,128,256,512),或者調整my.cnf參數,比較效果。另外需要注意的是,大部分mysql中間件對事務的處理,默認都是把sql發到主庫執行,所以只讀測試需要加上oltp-skip-trx=on來跳過測試中的顯式事務。 ps1: 只讀測試也可以使用share/tests/db/select.lua進行,但只是簡單的point select。 ps2: 我在用sysbench壓的時候,在mysql后端會話里有時看到大量的query cache lock,如果使用的是uniform取樣,最好把查詢緩存關掉。當然如果是做兩組性能對比壓測,因為都受這個因素影響,關心也不大。 ~~~ 3. 運行基準測試 1) 運行測試:混合操作測試 ~~~ sysbench --test=./sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=sysbenchtest --mysql-user=sysbench \ --mysql-password='4rfv$RFV' --num-threads=8 --oltp-table-size=100000 --oltp_tables_count=5 --oltp-read-only=off --report-interval=10 \ --rand-type=uniform --max-time=300 --max-requests=0 --percentile=99 run >> ./log/sysbench.log ~~~ 2) 如果多次測試清理記錄 ~~~ sysbench --test=./sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-host=127.0.0.1 --mysql-db=sysbenchtest --num-threads=8 \ --oltp-table-size=100000 --oltp_tables_count=5 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=600 --max-requests=0 \ --mysql-user=test --mysql-password='4rfv$RFV' cleanup ~~~ * 參數說明 ~~~ --num-threads=8 表示發起 8個并發連接 --oltp-read-only=off 表示不要進行只讀測試,也就是會采用讀寫混合模式測試 --report-interval=10 表示每10秒輸出一次測試進度報告 --rand-type=uniform 表示隨機類型為固定模式,其他幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托) --max-time=120 表示最大執行時長為 120秒,實際環境中建議30分鐘 --max-requests=0 表示總請求數為 0,因為上面已經定義了總執行時長,所以總請求數可以設定為 0;也可以只設定總請求數,不設定最大執行時長 --percentile=99 表示設定采樣比例,默認是 95%,即丟棄1%的長請求,在剩余的99%里取最大值 ~~~ 4. 分析調優效果:通過腳本控制測試,測試多次取平均值,運行腳本需要清空上一次的日志。 1) 參數分析 ~~~ queries performed: read: 938224 -- 讀總數 write: 268064 -- 寫總數 other: 134032 -- 其他操作總數(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等) total: 1340320 -- 全部總數 transactions: 67016 (1116.83 per sec.) -- 總事務數(每秒事務數) deadlocks: 0 (0.00 per sec.) -- 發生死鎖總數 read/write requests: 1206288 (20103.01 per sec.) -- 讀寫總數(每秒讀寫次數) other operations: 134032 (2233.67 per sec.) -- 其他操作總數(每秒其他操作次數) General statistics: -- 一些統計結果 total time: 60.0053s -- 總耗時 total number of events: 67016 -- 共發生多少事務數 total time taken by event execution: 479.8171s -- 所有事務耗時相加(不考慮并行因素) response time: -- 響應時長統計,主要參考指標 min: 4.27ms -- 最小耗時 avg: 7.16ms -- 平均耗時 max: 13.80ms -- 最長耗時 approx. 99 percentile: 9.88ms -- 超過99%平均耗時 Threads fairness: events (avg/stddev): 8377.0000/44.33 execution time (avg/stddev): 59.9771/0.00 ~~~ 5. 測試分析腳本 analysis_mysql.py,控制多次測試,然后取平均值 ~~~ #!/usr/bin/env python import re import os import configparser if (not os.path.exists("sysbench.log")): os.mknod("sysbench.log") else : os.remove("sysbench.log") os.mknod("sysbench.log") if (not os.path.exists("analysis.log")): os.mknod("analysis.log") logFile = open('sysbench.log','r') analysisFile = open('analysis.log','a+') configFile = "sysbench.conf" config = configparser.ConfigParser() config.read(configFile) host = config.get('config','dbhost') database = config.get('config','database') user = config.get('config','user') password = config.get('config','password') time = config.get('config','times') print(host) print(database) print(user) print(password) tableCount = config.get('config','--oltp-tables-count') tableSize = config.get('config','--oltp-table-size') threadNum = config.get('config','--num-threads') maxTime = config.get('config','--max-time') oltp = config.get('config','oltp') # 結果分析 def closeFile(file): file.close() def analysis(): print("開始分析...") transacion = [] readeWrite = [] mintime = [] avgtime = [] maxtime = [] approxtime = [] # 讀取文件數據 for line in logFile: transacion_persec = re.search(r'transactions:.*\((\d+\.*\d*).*\).*',line) readeWrite_persec = re.search(r'read/write requests:.*\((\d+\.*\d*).*\).*',line) mintime_response = re.search(r'min:\s*(\d+\.?\d*).*',line) avgtime_response = re.search(r'avg:\s*(\d+\.?\d*).*',line) maxtime_response = re.search(r'max:\s*(\d+\.?\d*).*',line) approxtime_response = re.search(r'approx.*?(\d+\.{1}\d*).*',line) if transacion_persec: transacion.append(transacion_persec.group(1)) elif readeWrite_persec: readeWrite.append(readeWrite_persec.group(1)) elif mintime_response: mintime.append(mintime_response.group(1)) elif avgtime_response: avgtime.append(avgtime_response.group(1)) elif maxtime_response: maxtime.append(maxtime_response.group(1)) elif approxtime_response: approxtime.append(approxtime_response.group(1)) sum = 0.0 # 統計事務 for data in transacion: sum += float(data) avgtransaction = ('%.2f'%(sum / len(transacion))) analysisFile.write("transacion每秒:" + str(avgtransaction) + "\n") sum = 0.0 # 統計讀寫 for data in readeWrite: sum += float(data) read_write = ('%.2f'%(sum / len(readeWrite))) analysisFile.write("read/write每秒:" + str(read_write) + "\n") sum = 0.0 # 統計最小時間 for data in mintime: sum += float(data) if len(mintime) !=0: min_time = ('%.2f'%(sum / len(mintime))) analysisFile.write("min time:" + str(min_time) + "\n") sum = 0.0 # 統計最大時間 for data in maxtime: sum += float(data) max_time = ('%.2f'%(sum / len(maxtime))) analysisFile.write("max time:" + str(max_time) + "\n") sum = 0.0 # 統計平均時間 for data in avgtime: sum += float(data) avg_time = ('%.2f'%(sum / len(avgtime))) analysisFile.write("avg time:" + str(avg_time) + "\n") analysisFile.write("="*20 + "\n") print("分析完成...") closeFile(analysisFile) # 數據準備 def prepare(): print("準備數據...表數:%s,記錄數:%s,測試線程數:%s,持續時間:%s"%(tableCount,tableSize,threadNum,maxTime)) os.system("sysbench --test=%s --mysql-host=%s --mysql-db=%s --mysql-user=%s --mysql-password='%s' --oltp-test-mode=complex --oltp-tables-count=%s --oltp-table-size=%s --threads=10 --ti me=%s --rand-init=on --report-interval=10 --mysql-table-engine=innodb prepare"%(oltp,host,database,user,password,tableCount,tableSize,maxTime)) # 測試函數 def experiment(): print("測試數據...") os.system("sysbench --test=%s --mysql-table-engine=innodb --mysql-host=%s --mysql-db=%s --mysql-user=%s --mysql-password='%s' --num-threads=%s --oltp-test-mode=complex --oltp-table-siz e=%s --oltp_tables_count=%s --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=%s --max-requests=0 --percentile=99 run >> ./sysbench.log"%(oltp,host,database,user,pass word,threadNum,tableSize,tableCount,maxTime)) # # # 清空數據 def clean(): print("清空測試數據庫...") os.system("sysbench --test=%s --mysql-table-engine=innodb --mysql-host=%s --mysql-db=%s --num-threads=8 --oltp-table-size=%s --oltp_tables_count=%s --oltp-read-only=off --report-interv al=10 --rand-type=uniform --max-time=600 --max-requests=0 --mysql-user=%s --mysql-password='%s' cleanup"%(oltp,host,database,tableSize,tableCount,user,password)) if __name__ == '__main__': for i in range(0,int(time)): prepare() experiment() clean() analysis() ~~~ * 配置文件 ~~~ [config] dbhost = 127.0.0.1 database = sysbenchtest user = sysbench password = 4rfv$RFV # oltp測試腳本路徑 oltp = /root/sysben/sysbench-0.5/sysbench/tests/db/oltp.lua # 測試次數 times = 5 --oltp-tables-count=5 --oltp-table-size=1000000 --num-threads=30 --max-time=600 ~~~ ## 2. 測試用例 > 測試用例: > 是為某個特殊目標而編制的一組測試輸入、執行條件以及預期結果,以便測試某個程序路徑或核實是否滿足特定需求 > 通俗的講,測試用例是指導我們進行具體測試的描述。 ![](https://box.kancloud.cn/4503334f9ca1bcfec42307285f2306da_1556x774.png) ![](https://box.kancloud.cn/52ffb0c062b1358b36904a4b326e34cc_1560x814.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看