php 压测流量回放,Web流量复制和压力测试工具Gor
Gor概述
Gor 是用 Golang 写的一个 HTTP 实时流量复制工具。只需要在 LB 或者 Varnish 入口服务器上执行一个进程,就可以把生产环境的流量复制到任何地方,比如 Staging 环境、Dev 环境。完美解决了 HTTP 层实时流量复制和压力测试的问题。
Image.png
Gor的功能
Gor 支持流量的放大和缩小、频率限制,这样不需要搭建和生产环境一致的服务器集群也可以正确测试。Gor 还支持根据正则表达式过滤流量,这意味着可以单独测试某个 API 服务。还可以修改 HTTP 请求头,比如替换 User-Agent, 或者增加某些 HTTP Header 。
Gor 还可以把请求记录到文件,以备回放和分析。Gor 支持和 ElasticSearch 集成,将流量存入 ES 进行实时分析。
Gor的安装
二进制版本
官方预编译版本使用比较简单,开箱即用。
通过以下地址下载最新版本
https://github.com/buger/gor/releases
Linux
$ wget https://github.com/buger/gor/releases/download/v0.12.1/gor_0.12.1_x64.tar.gz
$ tar xzvf gor_0.12.1_x64.tar.gz
$ cp gor /usr/local/bin
Mac
$ wget https://github.com/buger/gor/releases/download/v0.12.1/gor_0.12.1_mac.tar.gz
$ tar xzvf gor_0.12.1_mac.tar.gz
编译安装
搭建标准的Go语言环境,可参考http://golang.org/doc/code.html
并设置$GOPATH环境变量
获取源代码
$ go get github.com/buger/gor
编译
$ cd $GOPATH/src/github.com/buger/gor
$ go build
编译完成会产生一个gor二进制文件。
Gor实践
性能测试
可以将流量复制到文件,然后再对他们进行回放。回放的时候,流量会维持原始的时间间隔。如果你使用了百分比来进行速率限制,那么回放的速率会相应的增加或减少。有了这种速率限制,gor就可以用来进行压力测试。
#write to file
gor --input-raw :80 --output-file requests.log
#read from file
gor --input-file requests.gor --output-http"http://staging.com"
流量复制到文件
可以使用时间戳命名录制文件,默认情况下,文件是按“块”存储的,即文件大小到达上限后,添加后缀,并新建另一个文件,如下
gor ... --output-file %Y%m%d.log
#append false
20140608_0.log
20140608_1.log
20140609_0.log
20140609_1.log
默认是按“块”存储文件的方式,但是可以参数配置,--output-file-append,使用之后如下
gor ... --output-file %Y%m%d.log --output-file-append
#append true
20140608.log
20140609.log
时间格式化文件名的配置说明:
%Y: year including the century (at least 4 digits)
%m: month of the year (01..12)
%d: Day of the month (01..31)
%H: Hour of the day, 24-hour clock (00..23)
%M: Minute of the hour (00..59)
%S: Second of the minute (00..60)
默认格式是%Y%m%d%H
流量回放
目前,这种方式只支持"input-file",而且只能用百分比去控制回放速率。请注意,这个回放的速率比例是相对于input的。即按照录下来的流量的时间戳去进行回放。
# Replay from file on 2x speed
gor --input-file "requests.gor|200%" --output-http "staging.com"
上面的命令例子,是以2倍的速率回放。如果“input-flie”是多个文件,可以用正则去匹配,如“request*.gor|200%”
配合如下配置参数,可以更好的体现压力测试的效果。
--input-file-loop 重复循环执行input-file
--exit-after 30s 在30s后停止,可以控制压力测试的时间。分钟的单位是m
性能测试是gor比较常见的用途,其他常用命令参考“Gor常见命令”
Gor常用命令
简单的HTTP流量复制
$ gor --input-raw :80 --output-http "http://staging.com"
HTTP流量复制频率控制(获取每秒超过10个请求)
$ gor --input-tcp :28020 --output-http "http://staging.com|10"
HTTP流量复制缩小
$ gor --input-raw :80 --output-tcp "replay.local:28020|10%"
HTTP流量记录到本地文件
$ gor --input-raw :80 --output-file requests.gor
HTTP流量回放和压测
$ gor --input-file "requests.gor|200%" --output-http "staging.com"
HTTP流量过滤复制
$ gor --input-raw :8080 --output-http staging.com --output-http-url-regexp ^www.
自定义一些流量复制的参数
$ gor --input-raw :80 --output-http 192.168.2.6:8000 --http-allow-method POST --http-set-header 'User-Agent: Gor' -output-http-workers=1 -http-allow-url test.php
将流量复制两份到不同的测试服务
$ gor --input-tcp :28020 --output-http "http://staging.com" --output-http "http://dev.com"
将流量像负载均衡一样分配到不同的服务器
$ gor --input-tcp :28020 --output-http "http://staging.com" --output-http "http://dev.com" --split-output true
Gor配置参数
$ gor --help
-cpuprofile string
write cpu profile to file
-debug verbose
打开debug模式,显示所有接口的流量
-http-allow-header value
用一个正则表达式来匹配http头部,如果请求的头部没有匹配上,则被拒绝
gor --input-raw :8080 --output-http staging.com --http-allow-header api-version:^v1 (default [])
-http-allow-method value
类似于一个白名单机制来允许通过的http请求方法,除此之外的方法都被拒绝.
gor --input-raw :8080 --output-http staging.com --http-allow-method GET --http-allow-method OPTIONS (default [])
-http-allow-url value
一个正则表达式用来匹配url, 用来过滤完全匹配的的url,在此之外的都被过滤掉
gor --input-raw :8080 --output-http staging.com --http-allow-url ^www. (default [])
-http-disallow-header value
用一个正则表达式来匹配http头部,匹配到的请求会被拒绝掉
gor --input-raw :8080 --output-http staging.com --http-disallow-header "User-Agent: Replayed by Gor" (default [])
-http-disallow-url value
用一个正则表达式来匹配url,如果请求匹配上了,则会被拒绝
gor --input-raw :8080 --output-http staging.com --http-disallow-url ^www. (default [])
-http-header-limiter value
读取请求,基于FNV32-1A散列来拒绝一定比例的特殊请求
gor --input-raw :8080 --output-http staging.com --http-header-imiter user-id:25% (default [])
-http-original-host
在--output-http的输出中,通常gor会使用取代请求的http头,所以应该禁用该选项,保留原始的主机头
-http-param-limiter value
Takes a fraction of requests, consistently taking or rejecting a request based on the FNV32-1A hash of a specific GET param:
gor --input-raw :8080 --output-http staging.com --http-param-limiter user_id:25% (default [])
-http-rewrite-url value
Rewrite the request url based on a mapping:
gor --input-raw :8080 --output-http staging.com --http-rewrite-url /v1/user/([^\/]+)/ping:/v2/user/$1/ping (default [])
-http-set-header value
Inject additional headers to http reqest:
gor --input-raw :8080 --output-http staging.com --http-set-header 'User-Agent: Gor' (default [])
-http-set-param value
Set request url param, if param already exists it will be overwritten:
gor --input-raw :8080 --output-http staging.com --http-set-param api_key=1 (default [])
-input-dummy value
Used for testing outputs. Emits 'Get /' request every 1s (default [])
-input-file value
从一个文件中读取请求
gor --input-file ./requests.gor --output-http staging.com (default [])
-input-http value
从一个http接口读取请求
# Listen for http on 9000
gor --input-http :9000 --output-http staging.com (default [])
-input-raw value
Capture traffic from given port (use RAW sockets and require *sudo* access):
# Capture traffic from 8080 port
gor --input-raw :8080 --output-http staging.com (default [])
-input-tcp value
用来在多个gor之间流转流量
# Receive requests from other Gor instances on 28020 port, and redirect output to staging
gor --input-tcp :28020 --output-http staging.com (default [])
-memprofile string
write memory profile to this file
-middleware string
Used for modifying traffic using external command
-output-dummy value
用来测试输入,打印出接收的数据. (default [])
-output-file value
把进入的请求写入一个文件中
gor --input-raw :80 --output-file ./requests.gor (default [])
-output-http value
转发进入的请求到一个http地址上
# Redirect all incoming requests to staging.com address
gor --input-raw :80 --output-http http://staging.com (default [])
-output-http-elasticsearch string
把请求和响应状态发送到ElasticSearch:
gor --input-raw :8080 --output-http staging.com --output-http-elasticsearch 'es_host:api_port/index_name'
-output-http-redirects int
设置多少次重定向被允许
-output-http-stats
每5秒钟输出一次输出队列的状态
-output-http-timeout duration
指定http的request/response超时时间,默认是5秒
-output-http-workers int
gor默认是动态的扩展工作者数量,你也可以指定固定数量的工作者
-output-tcp value
用来在多个gor之间流转流量
# Listen for requests on 80 port and forward them to other Gor instance on 28020 port
gor --input-raw :80 --output-tcp replay.local:28020 (default [])
-output-tcp-stats
每5秒钟报告一次tcp输出队列的状态
-split-output true
By default each output gets same traffic. If set to true it splits traffic equally among all outputs.
-stats
打开输出队列的状态
-verbose
Turn on more verbose output
php 压测流量回放,Web流量复制和压力测试工具Gor相关推荐
- Web 应用性能和压力测试工具 Gor
Web 应用性能和压力测试工具 Gor 常见的 Web 应用的压力测试工具 Web 应用压力测试工具有很多,比如 Apache ab,node-ab,Apache JMeter, LoadRunner ...
- php 压测流量回放,终极 Web 应用性能和压力测试工具 Gor
常见的 Web 应用的压力测试工具 Web 应用压力测试工具有很多,比如 Apache ab,node-ab,Apache JMeter, LoadRunner, httperf.但是这些工具都没能解 ...
- 终极Web应用性能和压力测试工具Gor
什么是Gor 项目地址:https://github.com/buger/gor 官方描述 Gor is a simple http traffic replication tool written ...
- Windows开源Web服务器性能和压力测试工具
linux有很多开源工具用来测试服务器负载,而windows上非常少,几乎没有除了几个复杂的JMeter WET等 将两个好用的工具是Linux版本通过Cygwin移植过来,方便广大windows人员 ...
- 1 网站压力测试工具 WEB性能测试 Web Bench
Web Bench (网站压力测试工具) Web Bench是有名的网站压力测试工具,它是由 Lionbridge公司开发. Web Bench最多可以模拟3万个并发连接去测试网站的负载能力. We ...
- 从零开始的Nginx [ 8 ] --- nginx 的性能优化:ab接口压力测试工具,tomcat企业运维,WEB站点部署,项目上线
文章目录 nginx 性能优化 1.当前系统结构瓶颈 2.了解业务模式 3.性能与安全 4.系统与nginx性能优化 1.文件句柄 2.设置方式 3.系统全局性修该和用户局部性修改 4.进程局部性修改 ...
- Linux下四款Web服务器压力测试工具(http_load、webbench、ab、siege)介绍
一.http_load程序非常小,解压后也不到100K http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载.但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会 ...
- Linux下四款Web服务器压力测试工具…
一.http_load 程序非常小,解压后也不到100K http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载.但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不 ...
- Web服务器性能/压力测试工具http_load、webbench、ab、Siege使用教程
一.http_load 程序非常小,解压后也不到100K http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载.但是它不同于大多数压力测试工 具,它可以以一个单一的进程运行,一般 ...
最新文章
- 微信分享链接时,怎样才能带上带缩略图和简介?
- 【进阶技巧】如何绘制高颜值XMind思维导图?色彩使用很重要!
- Softmax(假神经网络)与词向量的训练
- (三)使用预定义模型QDirModel的例子
- 阶段3 1.Mybatis_08.动态SQL_01.mybatis中的动态sql语句-if标签
- 我的世界javamod怎么装_我的世界MOD安装方法图文教程_我的世界MOD怎么安装_牛游戏网...
- python毕业设计作品基于django框架外卖点餐系统毕设成品(7)中期检查报告
- sybase 错误码
- HP1010 不能连续打印维修一例
- How Did Watson Answer? —— Typing Coerced Candidate Answer
- PCB设计中抑制电磁干扰的几个准则及窍门
- 学习 Linux 有哪些好处?
- java 阿拉伯语_解析Json阿拉伯语文本
- python ppt 图片_python ppt 转 pdf 图片
- Android再进阶之广播发送、接收和注册过程
- Python环境搭建(一)
- windows 环境下node开发环境搭配问题
- 快手如何直播引流?快手直播推广方法分享
- java 代码性能优化_Java代码性能优化的几个小技巧
- 矩阵的快速转置和矩阵加法