關於goreplay
首先什麼是goreplay?
參照官方介紹nginx
GoReplay is the simplest and safest way to test your app using real traffic before you put it into production.git
GoReplay提供了重用現有流量進行測試的簡單想法。
大體工做流程以下:github
簡單來講就是goreplay抓取線上真實的流量,並將捕捉到的流量轉發到測試服務器上服務器
何時能夠試用goreplay?
簡單寫幾點場景,具體仍是根據實際需求來。markdown
上面大體說了goreplay是什麼以及什麼場景能夠用,下面記錄一下本身的實踐過程。
首先須要線上服務器root權限,這個須要謹慎使用!!!app
參照文檔,這一步很簡單less
wget [https://github.com/buger/goreplay/releases/download/v1.0-rc2/gor_1.0-RC2_x64.tar.gz](https://github.com/buger/goreplay/releases/download/v1.0-rc2/gor_1.0-RC2_x64.tar.gz) tar xvf gor_1.0-RC2_x64.tar.gz
-input-raw 抓取指定端口的流量 gor --input-raw :8080-output-stdout 打印到控制檯 -output-file 將請求寫到文件中 gor --input-raw :80 --output-file ./requests.gor-input-file 從文件中讀取請求,與上一條命令呼應 gor --input-file ./requests.gor-exit-after 5s 持續時間 -http-allow-url url白名單,其餘請求將會被丟棄 -http-allow-method 根據請求方式過濾 -http-disallow-url 趕上一個url相反,黑名單,其餘的請求會被捕獲到
實踐一下ide
sudo ./gor --input-raw :2051 --output-stdoutVersion: 1.0-RC21 45aea8cbxxxxxxx61a7600f384b263bb49dd60 1551432827638974877POST /absoxxxxlar HTTP/1.1Host: inner-xxxxxxxx.com Accept: */* Content-Length: 259Content-Type: application/x-www-form-urlencoded {"page":1,"count":10,"group":"exp_xxxxxr08","content_id":"77769a95f43438xxxx7f2e82c742","uid":"69xxxx68","device_code":"86093xxxxx2318","register_timestamp":1xxxxx75,"sex":0,"channel":"bxxxu","flavor":"","fancy":"","district":"\u5b81\u6ce2\u5e02"}1 1944f453259c95c1cc8b4cf1227104ed791c428c 1551432827642028761POST /sixxxxxlar HTTP/1.1Host: inner-xxxxxx.com Accept: */* Content-Length: 259Content-Type: application/x-www-form-urlencoded {"page":1,"count":10,"group":"expxxxx07","content_id":"9142a79e98b7xxxxxa67eaecd9de1","uid":"98xxxxx459","device_code":"868xxxx34136943","register_timestamp":15xxxx5663,"sex":2,"channel":"gdt79","flavor":"","fancy":"","district":"\u8861\u9633\u5e02"}1 28e10318f1d512f4e57b583aec4457e25daaadb6 1551432827657153296POST /abxxxxxilar HTTP/1.1Host: inner-xxxxxxxx.com Accept: */* Content-Length: 260Content-Type: application/x-www-form-urlencoded
sudo ./gor --input-raw :2051 --http-allow-url /recommend_you_like --output-file ./recommend_you_like.gor只篩選recommend_you_like接口的請求,保存在本地文件中
這邊其實是兩個實踐
第一個:保存流量到文件
第二個:抓取置頂url的流量
截圖能夠看到生成了一個文件性能
sudo ./gor --input-file ./recommend_you_like_0.gor --output-http="http://172.1.1.1:2051"
至測試環境的服務器上,查看日誌能夠到流量已經轉發過來測試
sudo ./gor --input-file 「./recommend_you_like_0.gor|200%」 --output-http="http://172.1.1.1:2051"
將請求以2倍的速度發出去
同時也支持限速
10% 20%等
關於限速還有另外一種方法——指定每秒的請求數
sudo ./gor --input-file 「./recommend_you_like_0.gor」 --output-http="http://172.1.1.1:2051|50"
更多參考官方文檔:https://github.com/buger/goreplay/wiki/Getting-Started