-
Notifications
You must be signed in to change notification settings - Fork 113
/
16e-customize-bench.go
56 lines (44 loc) · 954 Bytes
/
16e-customize-bench.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/guonaihong/gout"
"github.com/guonaihong/gout/filter"
"sync/atomic"
"time"
)
const (
benchNumber = 30000
benchConcurrent = 30
)
func server() {
router := gin.New()
router.POST("/", func(c *gin.Context) {
c.String(200, "hello world:gout")
})
router.Run()
}
func customize() {
i := int32(0)
err := filter.NewBench().
Concurrent(benchConcurrent).
Number(benchNumber).
Loop(func(c *gout.Context) error {
// 下面的代码,每次生成不一样的http body 用于压测
uid := uuid.New()
id := atomic.AddInt32(&i, 1)
c.POST(":8080").SetJSON(gout.H{"sid": uid.String(),
"appkey": fmt.Sprintf("ak:%d", id),
"text": fmt.Sprintf("test text :%d", id)})
return nil
}).Do()
if err != nil {
fmt.Printf("err = %v\n", err)
}
}
func main() {
go server()
time.Sleep(300 * time.Millisecond)
customize()
}