本次版本主要特性是 benchmark 功能。使用 gout 嵌入到_test.go 里面,git 和 CI/CD 流程打通,代码合并到 git master,自动启动测试服务镜像。压测接口。有此功能可更方便观察接口性能指标。很多朋友喜欢使用 apache ab 观察性能,拥有此版本的 gout 助你很方便的开发此类轮子。更多姿势等你挖掘。。。
其他主要是细节处优化,越来越多的朋友在使用 gout,提出了很多宝贵意见,和边界问题,都逐一优化解决。
https://github.com/guonaihong/gout
值越大越好
package main
import (
"fmt"
"github.com/guonaihong/gout"
"time"
)
const (
benchTime = 10 * time.Second
benchConcurrent = 30
)
func main() {
err := gout.
POST(":8080"). //压测本机 8080 端口
SetJSON(gout.H{"hello": "world"}). //设置请求 body 内容
Filter(). //打开过滤器
Bench(). //选择 bench 功能
Concurrent(benchConcurrent). //并发数
Durations(benchTime). //压测时间
Do()
if err != nil {
fmt.Printf("%v\n", err)
}
}
下面的例子,起了20并发。对:8080端口的服务,压测总次数为3000次,其中每秒发送1000次。内容为json结构
package main
import (
"fmt"
"github.com/guonaihong/gout"
)
const (
benchNumber = 3000
benchConcurrent = 20
)
func main() {
err := gout.
POST(":8080"). //压测本机8080端口
SetJSON(gout.H{"hello": "world"}). //设置请求body内容
Filter(). //打开过滤器
Bench(). //选择bench功能
Rate(1000). //每秒发1000请求
Concurrent(benchConcurrent). //并发数
Number(benchNumber). //压测次数
Do()
if err != nil {
fmt.Printf("%v\n", err)
}
}