
golang 实现的 http 请求库。本次版本带来一些细节上的优化。http 请求库作用是让你发送 json/formdata 之类数据更 easy,bind 数据更爽。gout 除了是 restful api 库还是压测 lib,可以完成 ab, wrk 完成的工作。
本次版本是 v0.0.12
https://github.com/guonaihong/gout
提升压测子模块的吞吐效率。
自定义压测函数,构造每次不一样的 http request 数据。 相比 wrk 需要写 lua,在 go lib 里面解决自定义压测会更 easy
package main import ( "fmt" "github.com/google/uuid" "github.com/guonaihong/gout" "github.com/guonaihong/gout/filter" "sync/atomic" ) func main() { i := int32(0) err := filter.NewBench(). Concurrent(30). //开 30 个 go 程 Number(30000). //压测 30000 次 Loop(func(c *gout.Context) error { // 下面的代码,每次生成不一样的 http body 用于压测 uid := uuid.New() //生成 uuid id := atomic.AddInt32(&i, 1) //生成 id, 可以理解为++i,线程安全版本 c.POST(":1234").SetJSON(gout.H{"sid": uid.String(), "appkey": fmt.Sprintf("ak:%d", id), "text": fmt.Sprintf("test text :%d", id)}) //这里不要运行 Do()函数 return nil }).Do() if err != nil { fmt.Printf("err = %v\n", err) } } 1 wysnylc 2020-05-25 10:18:45 +08:00 python 党出来,就照这样写个轮子 |
2 lasuar 2020-05-25 10:25:04 +08:00 也用 go,给个 star ! |
3 guonaihong OP @lasuar 感谢支持。。。 |
4 guonaihong OP @wysnylc 看过你的留言,哈哈,你不是用 java 的吗。。。 |
5 wysnylc 2020-05-25 18:45:14 +08:00 @guonaihong #4 Java 只是副业,主业是键盘侠 |
6 prenwang 2020-06-04 22:03:14 +08:00 @guonaihong 感谢造出这么好用的裤子. |
7 guonaihong OP @prenwang 也感谢你的使用,哈哈。。。 |
8 u823tg 2020-06-08 14:48:37 +08:00 很 nice,就是最近不怎么用 go 了,我果然是个见异思迁的。哈哈哈 |
9 johng 2020-06-11 00:58:44 +08:00 @guonaihong 架构图画得不错,是用的 processon 吗? |
10 guonaihong OP @johng 是的。 |
11 guonaihong OP @u823tg 哈哈。。。下次可以玩 rust 。 |