V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
guonaihong
V2EX  ›  Go 编程语言

gout v0.0.4 版本发布,为 RESTful 接口使用插上 benchmark 的翅膀

  •  
  •   guonaihong ·
    guonaihong · 2019-12-09 09:10:18 +08:00 · 2962 次点击
    这是一个创建于 1594 天前的主题,其中的信息可能已经有所发展或是发生改变。

    benchmark

    本次版本主要特性是 benchmark 功能。使用 gout 嵌入到_test.go 里面,git 和 CI/CD 流程打通,代码合并到 git master,自动启动测试服务镜像。压测接口。有此功能可更方便观察接口性能指标。很多朋友喜欢使用 apache ab 观察性能,拥有此版本的 gout 助你很方便的开发此类轮子。更多姿势等你挖掘。。。

    其他

    其他主要是细节处优化,越来越多的朋友在使用 gout,提出了很多宝贵意见,和边界问题,都逐一优化解决。

    项目地址

    https://github.com/guonaihong/gout

    benchmark 性能如何

    值越大越好

    gout-vs-ab.png

    example

    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)
    	}
    }
    
    第 1 条附言  ·  2019-12-09 12:53:59 +08:00

    example2(控制压测频率)

    下面的例子,起了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)
    	}
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2811 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:37 · PVG 17:37 · LAX 02:37 · JFK 05:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.