http流量复制工具goreplay

 

场景一个待测服务,用来处理线上千万量级用户的各式请求;问题如果数据交换使用比较简单的xml、json等,可以...



场景

一个待测服务,用来处理线上千万量级用户的各式请求;

问题如果数据交换使用比较简单的xml、json等,可以设计各类case,去覆盖正常、异常的情况,但是如果数据交换格式比较复杂,且服务逻辑也比较复杂,这样的话就需要对代码逻辑非常熟悉才能设计全面的case;但是如果没有足够的时间去熟悉代码逻辑,那怎么能保证各类case都能覆盖到呢?

解决方案今天介绍一款能快速解决上述问题的工具——goreplay

工具原理官方介绍:

GoReplay is the simplest and safest way to test your app using real traffic before you put it into production.
As your application grows, the effort required to test it also grows exponentially. GoReplay offers you the simple idea of reusing your existing traffic for testing, which makes it incredibly powerful. Our state of art technique allows to analyze and record your application traffic without affecting it. This eliminates the risks that come with putting a third party component in the critical path.
GoReplay increases your confidence in code deployments, configuration changes and infrastructure changes. Did we mention that no coding is required?
Here is basic workflow: The listener server catches http traffic and sends it to the replay server or saves to file. The replay server forwards traffic to a given address.

大概意思就是:goreplay是一款从生产环境copy流量到测试环境的工具,且不会影响生产环境的业务相应,又能很简单的达到复用http请求来进行稳定性测试 的目的;



使用方法这个工具可以直接从github上下载成品,如果你的服务器是centos7以上,应该可以直接解压后使用;
https://github.com/buger/goreplay

解压后只有一个文件:goreplay
他会依赖两个系统库,一般系统已经预置,如果没有,可以手动安装,详见这里:
https://github.com/buger/goreplay/wiki/Compilation

简单的场景下,这个工具使用方法非常简单
sudo ./goreplay
执行

example:将请求到本机80端口的http请求,毫无变化的转发到192.168.100.100的1234端口上
./goreplay --input-raw :80 --output-http="http://192.168.100.100:1234"


基本参数介绍由于文档比较少,从官网摘了一些基本参数:

Available inputs:
–input-raw - used to capture HTTP traffic, you should specify IP address or interface and application port. (指定IP地址和端口捕获HTTP流量)
–input-file - accepts file which previously was recorded using –output-file. (使用之前通过输出记录下来的请求文件)


Available outputs:
–output-http - replay HTTP traffic to given endpoint, accepts base url. (将复制的请求打到哪里去)
–output-file - records incoming traffic to the file. (记录复制的请求信息到一个文件里,用于后续的测试)
–output-stdout - used for debugging, outputs all data to stdout.(输出调试信息到console)

以上只是一些基本参数,这个工具还支持一些稍复杂的操作,比如将生产环境的请求按某些条件过滤之后,再进行测试等功能;
详见官方wiki:
https://github.com/buger/goreplay/wiki/The-Basics


优缺点这个工具相比之前接触的一些工具的优点在于,在centos7以上的机器上不需编译或安装有内存或cpu消耗的程序,拷贝过来就可以直接使用;
缺点是这类工具的通病,需要操作生产环境服务器;

但是有需要 快速验证服务稳定性 需求的话,还是非常方便的;

(部分内容摘自goreplay github官网wiki)


    关注 搜狗测试


微信扫一扫关注公众号

0 个评论

要回复文章请先登录注册