web api性能測試使用wrk

web api性能測試

這邊簡單的給出shell腳本

注意先安裝:wrk和gnuplot

#!/bin/bash# Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
# Use of this source code is governed by a MIT style
# license that can be found in the LICENSE file.: << EOF
API 性能測試腳本,會自動執行 wrk 命令,采集數據、分析數據并調用 gnuplot 畫圖使用方式 ( 測試 API 性能):
1. 啟動 iam-apiserver(8080端口)
2. 執行測試腳本: ./wrktest.sh腳本會生成 .dat 的數據文件,每列含義為:并發數 QPS 平均響應時間 成功率使用方式 (對比2次測試結果)
1. 性能測試:./wrktest.sh iam-apiserver http://127.0.0.1:8080/healthz
2. 執行命令: ./wrktest.sh diff apiserver.dat http.dat> Note: 需要確保系統安裝了 wrk 和 gnuplot 工具
EOFiamroot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
wrkdir="${iamroot}/_output/wrk"
jobname="apiserver"
duration="300s"
threads=$((3 * `grep -c processor /proc/cpuinfo`))source "${iamroot}/scripts/lib/color.sh"# Set wrk options
iam::wrk::setup() {#concurrent="200 500 1000 3000 5000 10000 15000 20000 25000 50000 100000 200000 500000 1000000"concurrent="200 500 1000 3000 5000 10000 15000 20000 25000 50000"cmd="wrk -t${threads} -d${duration} -T30s --latency"
}# Print usage infomation
iam::wrk::usage()
{cat << EOFUsage: $0 [OPTION] [diff] URL
Performance automation test script.URL                    HTTP request url, like: http://127.0.0.1:8080/healthzdiff                   Compare two performance test resultsOPTIONS:-h                     Usage information-n                     Performance test task name, default: apiserver-d                     Directory used to store performance data and gnuplot graphic, default: _output/wrkReprot bugs to <colin404@foxmail.com>.
EOF
}# Convert plot data to useable data
function iam::wrk::convert_plot_data()
{echo "$1" | awk -v datfile="${wrkdir}/${datfile}" ' {if ($0 ~ "Running") {common_time=$2}
if ($0 ~ "connections") {connections=$4common_threads=$1
}
if ($0 ~ "Latency   ") {avg_latency=convertLatency($2)
}
if ($0 ~ "50%") {p50=convertLatency($2)
}
if ($0 ~ "75%") {p75=convertLatency($2)
}
if ($0 ~ "90%") {p90=convertLatency($2)
}
if ($0 ~ "99%") {p99=convertLatency($2)
}
if ($0 ~ "Requests/sec") {qps=$2
}
if ($0 ~ "requests in") {allrequest=$1
}
if ($0 ~ "Socket errors") {err=$4+$6+$8+$10
}
}
END {
rate=sprintf("%.2f", (allrequest-err)*100/allrequest)
print connections,qps,avg_latency,rate >> datfile
}function convertLatency(s) {if (s ~ "us") {sub("us", "", s)return s/1000}
if (s ~ "ms") {sub("ms", "", s)return s
}
if (s ~ "s") {sub("s", "", s)return s * 1000
}
}'
}# Remove existing data file
function iam::wrk::prepare()
{rm -f ${wrkdir}/${datfile}
}# Plot according to gunplot data file
function iam::wrk::plot() {gnuplot <<  EOF
set terminal png enhanced #輸出格式為png文件
set ylabel 'QPS'
set xlabel 'Concurrent'
set y2label 'Average Latency (ms)'
set key top left vertical noreverse spacing 1.2 box
set tics out nomirror
set border 3 front
set style line 1 linecolor rgb '#00ff00' linewidth 2 linetype 3 pointtype 2
set style line 2 linecolor rgb '#ff0000' linewidth 1 linetype 3 pointtype 2
set style data linespointsset grid #顯示網格
set xtics nomirror rotate #by 90#只需要一個x軸
set mxtics 5
set mytics 5 #可以增加分刻度
set ytics nomirror
set y2ticsset autoscale  y
set autoscale y2set output "${wrkdir}/${qpsttlb}"  #指定數據文件名稱
set title "QPS & TTLB\nRunning: ${duration}\nThreads: ${threads}"
plot "${wrkdir}/${datfile}" using 2:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" axis x1y1 t "QPS","${wrkdir}/${datfile}" using 3:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#0000CD" axis x2y2 t "Avg Latency (ms)"unset y2tics
unset y2label
set ytics nomirror
set yrange[0:100]
set output "${wrkdir}/${successrate}"  #指定數據文件名稱
set title "Success Rate\nRunning: ${duration}\nThreads: ${threads}"
plot "${wrkdir}/${datfile}" using 4:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#F62817" t "Success Rate"
EOF
}# Plot diff graphic
function iam::wrk::plot_diff()
{gnuplot <<  EOF
set terminal png enhanced #輸出格式為png文件
set xlabel 'Concurrent'
set ylabel 'QPS'
set y2label 'Average Latency (ms)'
set key below left vertical noreverse spacing 1.2 box autotitle columnheader
set tics out nomirror
set border 3 front
set style line 1 linecolor rgb '#00ff00' linewidth 2 linetype 3 pointtype 2
set style line 2 linecolor rgb '#ff0000' linewidth 1 linetype 3 pointtype 2
set style data linespoints#set border 3 lt 3 lw 2   #這會讓你的坐標圖的border更好看
set grid #顯示網格
set xtics nomirror rotate #by 90#只需要一個x軸
set mxtics 5
set mytics 5 #可以增加分刻度
set ytics nomirror
set y2tics#set pointsize 0.4 #點的像素大小
#set datafile separator '\t' #數據文件的字段用\t分開set autoscale  y
set autoscale y2#設置圖像的大小 為標準大小的2倍
#set size 2.3,2set output "${wrkdir}/${t1}_${t2}.qps.ttlb.diff.png"  #指定數據文件名稱
set title "QPS & TTLB\nRunning: ${duration}\nThreads: ${threads}"
plot "/tmp/plot_diff.dat" using 2:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" axis x1y1 t "${t1} QPS","/tmp/plot_diff.dat" using 5:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE82EE" axis x1y1 t "${t2} QPS","/tmp/plot_diff.dat" using 3:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#0000CD" axis x2y2 t "${t1} Avg Latency (ms)", "/tmp/plot_diff.dat" using 6:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#6495ED" axis x2y2 t "${t2} Avg Latency (ms)"unset y2tics
unset y2label
set ytics nomirror
set yrange[0:100]
set output "${wrkdir}/${t1}_${t2}.successrate.diff.png"  #指定數據文件名稱
set title "Success Rate\nRunning: ${duration}\nThreads: ${threads}"
plot "/tmp/plot_diff.dat" using 4:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" t "${t1} Success Rate","/tmp/plot_diff.dat" using 7:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE82EE" t "${t2} Success Rate"
EOF
}# Start API performance testing
iam::wrk::start_performance_test() {iam::wrk::preparefor c in ${concurrent}dowrkcmd="${cmd} -c ${c} $1"echo "Running wrk command: ${wrkcmd}"result=`eval ${wrkcmd}`iam::wrk::convert_plot_data "${result}"doneecho -e "\nNow plot according to ${COLOR_MAGENTA}${wrkdir}/${datfile}${COLOR_NORMAL}"iam::wrk::plot &> /dev/nullecho -e "QPS graphic file is: ${COLOR_MAGENTA}${wrkdir}/${qpsttlb}${COLOR_NORMAL}
Success rate graphic file is: ${COLOR_MAGENTA}${wrkdir}/${successrate}${COLOR_NORMAL}"
}while getopts "hd:n:" opt;docase ${opt} ind)wrkdir=${OPTARG};;n)jobname=${OPTARG};;?)iam::wrk::usageexit 0;;esac
doneshift $(($OPTIND-1))mkdir -p ${wrkdir}
case $1 in"diff")if [ "$#" -lt 3 ];theniam::wrk::usageexit 0fit1=$(basename $2|sed 's/.dat//g') # 對比圖中紅色線條名稱t2=$(basename $3|sed 's/.dat//g') # 對比圖中粉色線條名稱join $2 $3 > /tmp/plot_diff.datiam::wrk::plot_diff `basename $2` `basename $3`exit 0;;*)if [ "$#" -lt 1 ];theniam::wrk::usageexit 0fiurl="$1"qpsttlb="${jobname}_qps_ttlb.png"successrate="${jobname}_successrate.png"datfile="${jobname}.dat"iam::wrk::setupiam::wrk::start_performance_test "${url}";;
esac

直接使用wrk命令

wrk -t144 -c3000 -d30s -T30s --latency 你的url

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/211722.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/211722.shtml
英文地址,請注明出處:http://en.pswp.cn/news/211722.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

vue 學習 -- day39(vue3 — reactive 對比 ref)

從定義數據角度對比&#xff1a; ref用來定義&#xff1a;基本類型數據。reactive用來定義&#xff1a;對象&#xff08;或數組&#xff09;類型數據。備注&#xff1a;ref也可以用來定義對象&#xff08;或數組&#xff09;類型數據, 它內部會自動通過reactive轉為代理對象。從…

如何防止惡意調用和攻擊對抖音商品詳情API的影響?

防止惡意調用和攻擊對抖音商品詳情API的影響是開發者和平臺必須關注的問題。惡意調用和攻擊可能導致服務中斷、數據泄露或其他安全問題&#xff0c;對平臺和用戶造成損失。本文將介紹一些常見的惡意調用和攻擊方式&#xff0c;并提出相應的防范措施&#xff0c;以確保抖音商品詳…

JavaScript函數概念、聲明、調用

JavaScript函數是一段可以重復使用的代碼塊&#xff0c;用于執行特定的任務。函數封裝了一定的邏輯&#xff0c;可以接收輸入參數并返回結果&#xff0c;使得代碼更加模塊化&#xff0c;可讀性更高。 函數聲明可以使用function關鍵字來創建&#xff0c;通常包括函數名、參數列…

python畫動漫形象(魔法少女小圓曉美焰,super beautiful)

1.源代碼 import turtle as te import time WriteStep 15 # 貝塞爾函數的取樣次數 Speed 5 Width 600 # 界面寬度 Height 500 # 界面高度 Xh 0 # 記錄前一個貝塞爾函數的手柄 Yh 0 def Bezier(p1, p2, t): # 一階貝塞爾函數 return p1 * (1 - t) p2 * t def Bezier_2(x1…

stu06-VSCode里的常用快捷鍵

Alt Z&#xff1a;文字自動換行。當一行的文字太長時&#xff0c;可以使用。或者查看→自動換行Alt Shift ↓ &#xff1a;快速復制當前行到下一行Alt Shift ↑ &#xff1a;快速復制當前行到上一行Alt B&#xff1a;在默認瀏覽器中打開當前.html文件Ctrl Enter&#xf…

深入學習之anaconda、pytorch、cuda安裝

文章目錄 1. 安裝CUDA與CUDNN2. Anaconda安裝PyTorch3. notebook添加自己創建的環境4. Anaconda安裝相關的庫5. GPU測試 1. 安裝CUDA與CUDNN csdn大佬安裝步驟 【CUDA】cuda安裝 &#xff08;windows版&#xff09; 查看此電腦的CUDA版本配置 自己電腦上GPU使用的詳細參數 n…

端口復用和重映射

一、端口復用 &#xff08;1&#xff09;端口復用概念 端口復用是將一個I/O賦予多個功能&#xff0c;通過設置I/O的工作模式來切換不同的功能。 STM32有很多的內置外設&#xff0c;這些外設的外部引腳都是與GPIO復用的。也就是說&#xff0c;一個GPIO如果可以復用為內置外設的…

《PySpark大數據分析實戰》圖書上線啦

《PySpark大數據分析實戰》圖書上線啦 《PySpark大數據分析實戰》圖書上線啦特殊的日子關于創作關于數據關于Spark關于PySpark關于圖書/專欄 《PySpark大數據分析實戰》圖書上線啦 特殊的日子 不知不覺一轉眼入駐CSDN已經滿一年了&#xff0c;這真是一個充滿意義的特殊的日子&…

Linux命令詳解./configure、make、make install 命令學習

文章來自Linux命令詳解./configure、make、make install 命令-CSDN博客 文章目錄 1 編譯安裝命令詳解 1.1 簡介 1.2 詳細解釋 1.2.1 configure命令 1.2.2 make 1.2.3 make insatll 1.2.4 configure和make中的DESTDIR和PREFIX區別 1.2.4.1 configure中的PREFIX 1.2.4.2 make ins…

sfp8472學習CDR

1,cdr名稱解釋 因為光信號傳輸至一定距離的時候,通常是長距離傳輸,其波形會出現一定程度的失真,接收端接收到的信號是一個個長短不一的脈沖信號,這個時候在接收端,我們就無法得到我們需要的數據。所以,這個時候就需要有信號的再生,信號的再生功能為再放大、再整形和再…

[足式機器人]Part2 Dr. CAN學習筆記-自動控制原理Ch1-2穩定性分析Stability

本文僅供學習使用 本文參考&#xff1a; B站&#xff1a;DR_CAN Dr. CAN學習筆記-自動控制原理Ch1-2穩定性分析Stability 0. 序言1. 穩定的分類2. 穩定的對象3. 穩定的系統4. 系統穩定性的討論5. 補充內容——Transfer Function(傳遞函數) - nonzero Initial Condition(非零初始…

高防IP防御效果怎么樣,和VPN有區別嗎

高防IP主要是用于防御網絡攻擊&#xff0c;可以抵御各種類型的DDoS攻擊&#xff0c;隱藏源IP地址&#xff0c;提高網絡安全性和用戶體驗。主要目的是解決外部網絡攻擊問題&#xff0c;保護網絡安全&#xff0c;避免因攻擊而導致的業務中斷和數據泄露等問題。 而VPN則是一種可以…

ubuntu20 安裝docker

一.官網安裝文檔 &#xff08;基本按官方文檔安裝&#xff09; Install Docker Engine on Ubuntu | Docker Docs 二.安裝步驟 1.docker 需要64位操作系統、linux內核要在3.1以上 #uname -r 2.卸載可能存在的舊版本 #sudo apt-get remove docker docker-engine docker-ce …

《Mamba: Linear-Time Sequence Modeling with Selective State Spaces》閱讀筆記

論文標題 《Mamba: Linear-Time Sequence Modeling with Selective State Spaces》 作者 Albert Gu 和 Tri Dao 初讀 摘要 Transformer 架構及其核心注意力模塊 地位&#xff1a;目前深度學習領域普遍的基礎模型。 為了解決 Transformers 在長序列上的計算效率低下的問題…

【193】Java8調用POI 5.2.5生成帶圖片的Excel文件

本文假定 Excel 文件中保存的是員工數據&#xff0c;并且數據中帶有員工的頭像。代碼支持的圖片格式有png、bmp、jpg、gif。但是這里需要注意&#xff0c;有些網站上下載的圖片雖然后綴名是 jpg&#xff0c;但是文件二進制內容的格式是 WebP 的。Java8 目前官方api不支持 WebP …

【代碼隨想錄算法訓練營-第四天】【鏈表】24,19, 面試題 02.07,142

24. 兩兩交換鏈表中的節點 第一遍-遞歸-小看了一下題解 思路&#xff1a; 讀了兩遍題目才理解…相鄰節點的交換&#xff0c;這個操作很容易實現&#xff0c;但需要一個tmpNode因為是鏈表的題目&#xff0c;沒開始思考之前先加了dummyNode&#xff0c;還真管用把dummyNode作為…

空氣質量數據和氣象數據

1、北京、上海、廣州的空氣質量數據和氣象數據 要素如下&#xff1a; 逐日數據 時間跨度&#xff1a;2014.1.1-2022.3.31&#xff0c;共3012條數據 數據質量&#xff1a;98% 城市&#xff1a;只有北京、上海、廣州 可以用作論文數據 數據來源&#xff1a;中國環境監測總站…

23. 合并 K 個升序鏈表 --力扣 --JAVA

題目 給你一個鏈表數組&#xff0c;每個鏈表都已經按升序排列。 請你將所有鏈表合并到一個升序鏈表中&#xff0c;返回合并后的鏈表。 解題思路 對每個鏈表的首節點進行比較&#xff0c;獲取當前的最小節點&#xff1b;將每個階段的最小節點進行鏈接&#xff1b; 代碼展示 c…

亞馬遜云科技re_Invent 2023產品體驗:亞馬遜云科技產品應用實踐 國賽選手帶你看Elasticache Serverless

拋磚引玉 講一下作者背景&#xff0c;曾經參加過國內世界技能大賽云計算的選拔&#xff0c;那么在競賽中包含兩類&#xff0c;一類是架構類競賽&#xff0c;另一類就是TroubleShooting競賽&#xff0c;對應的分別為AWS GameDay和AWS Jam&#xff0c;想必也有朋友玩過此類競賽&…

4.權限特權轉移代碼

核心文件用戶文件引導文件 核心文件 ;------------------------新增--------------------------------; 本文件涉及了權限, 將使用調用門描述符來處理 低權限到高權限的轉移;------------------------權限---------------------------- ;此文件延用上個CORE.asm. 并做出一些修…