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

Python+Jmeter實現(xiàn)自動化性能壓測的流程步驟

 更新時間:2024年05月23日 09:20:50   作者:咖啡加剁椒③  
性能測試是一個全棧工程師/架構(gòu)師必會的技能之一,只有學(xué)會性能測試,才能根據(jù)得到的測試報告進(jìn)行分析,找到系統(tǒng)性能的瓶頸所在,而這也是優(yōu)化架構(gòu)設(shè)計中重要的依據(jù),本文給大家介紹了Python+Jmeter實現(xiàn)自動化性能壓測的流程步驟,需要的朋友可以參考下

Step01: Python腳本開發(fā)

文件路徑:D://wl//testproject//Fone-grpc//project1//test_client.py

Python 腳本作用:

1.通過 grpc 調(diào)用底層 c++ 的接口,做數(shù)據(jù)庫的數(shù)據(jù)插入與查詢操作,然后將返回的結(jié)果進(jìn)行拼接與輸出。

2.代碼里面將每一次調(diào)用后返回的內(nèi)容進(jìn)行拼接后,并做了成功信息的統(tǒng)計,輸出成功的次數(shù)為3,輸出后會轉(zhuǎn)給 jmeter 里面的腳本獲取。

from __future__ import print_function
import logging
import sys
import grpc
import Storage_pb2      # Storage_pb2.py which contains our generated request and response classes
import StorageService_pb2_grpc # StorageService_pb2_grpc.py which contains our generated client and server classes.
 
host="10.10.1.117:50066"
 
def run():
    result=""
    with grpc.insecure_channel(host) as channel:
        resp0=StorageService_pb2_grpc.FOneStorageStub(channel).InsertKVS(Storage_pb2.PUpsertKVS(
            DBName="MergeLog",TableName="MergeLog",KeyValues=[{"Key":b'',"Key":b''}],Upsert=True,Transaction=True
        ))
        result+=str(resp0)
 
    with grpc.insecure_channel(host) as channel:
        stud1=StorageService_pb2_grpc.FOneStorageStub(channel)
        resp1=stud1.InsertV(Storage_pb2.PInsertV(DBName="MergeLog", TableName="MergeLog", Value=b"1"))
        result += str(resp1)
     
    with grpc.insecure_channel(host) as channel:
        stud2=StorageService_pb2_grpc.FOneStorageStub(channel)
        resp2=stud2.FindOne(Storage_pb2.PFindK(DBName="MergeLog", TableName="MergeLog", Key="1"))
        result += str(resp2)
 
    result=result.replace("\n", " ")
    result=result.count("Successful return: 0")
    print(result)
 
 
if __name__ == '__main__':
    logging.basicConfig()
    run()

PS:在本地調(diào)試好腳本,確保符合預(yù)期。

Step02: Jmeter 創(chuàng)建 beanshell 取樣器

腳本內(nèi)容如下:

import java.io.BufferedReader;
import java.io.InputStreamReader;
 
log.info("----------------------------start to exe");
String command = "cmd /c python D://wl//testproject//Fone-grpc//project1//test_client.py"; //定義要執(zhí)行的python文件路徑
String var;
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);  //執(zhí)行上面的python腳本
pr.waitFor()
BufferedReader b = new BufferedReader(new InputStreamReader(pr.getInputStream())); // 轉(zhuǎn)換執(zhí)行腳本后的返回響應(yīng)
String line = "";
StringBuilder response = new StringBuilder();
while ((line = b.readLine()) != null) {
     response.append(line);
} 
String response_data = response.toString();
log.info(response_data);
if(response_data.equals("3")){ // 判斷響應(yīng)的內(nèi)容是否有3次,如果不是3次就表示執(zhí)行失敗了
 log.info("---------------------------success end exe");
}else{
 log.error("--------------------------failed end exe"); //這里的輸出一次會記錄一次失敗次數(shù)
}
b.close();

Step03: 執(zhí)行效果

通過 jmeter 工具進(jìn)行并發(fā)操作,對后端底層接口進(jìn)行壓力測試,效果不錯,效果圖如下所示。

Step04: Jmeter日志輸出

2023-02-22 17:26:08,539 INFO o.a.j.t.JMeterThread: Stopping because end time detected by thread: 線程組--python 1-33
2023-02-22 17:26:08,539 INFO o.a.j.t.JMeterThread: Thread finished: 線程組--python 1-33
2023-02-22 17:26:08,597 INFO o.a.j.u.BeanShellTestElement: 3
2023-02-22 17:26:08,597 INFO o.a.j.u.BeanShellTestElement: ---------------------------success end exe
2023-02-22 17:26:08,598 INFO o.a.j.t.JMeterThread: Stopping because end time detected by thread: 線程組--python 1-82
2023-02-22 17:26:08,598 INFO o.a.j.t.JMeterThread: Thread finished: 線程組--python 1-82
2023-02-22 17:26:08,608 INFO o.a.j.u.BeanShellTestElement: 2
2023-02-22 17:26:08,608 ERROR o.a.j.u.BeanShellTestElement: --------------------------failed end exe

到此這篇關(guān)于Python+Jmeter實現(xiàn)自動化性能壓測的流程步驟的文章就介紹到這了,更多相關(guān)Python+Jmeter性能壓測內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

屯门区| 利津县| 新宾| 巧家县| 堆龙德庆县| 林西县| 克拉玛依市| 温宿县| 五寨县| 石城县| 永顺县| 拉萨市| 什邡市| 锦州市| 游戏| 平山县| 肃宁县| 德昌县| 鄯善县| 都匀市| 深圳市| 修文县| 武鸣县| 永春县| 内丘县| 佳木斯市| 社旗县| 白水县| 达日县| 策勒县| 阳西县| 天津市| 巴中市| 荆门市| 察隅县| 遂溪县| 襄垣县| 尼玛县| 开鲁县| 桑日县| 马公市|