V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
guonaihong

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

  •  
  •   guonaihong ·
    guonaihong · Dec 9, 2019 · 3321 views
    This topic created in 2340 days ago, the information mentioned may be changed or developed.

    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)
    	}
    }
    
    Supplement 1  ·  Dec 9, 2019

    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)
    	}
    }
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   957 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:08 · PVG 04:08 · LAX 13:08 · JFK 16:08
    ♥ Do have faith in what you're doing.